openRateLimited will execute a closure under a rate limiter watch
(fn func() (io.ReadCloser, error))
| 1761 | |
| 1762 | // openRateLimited will execute a closure under a rate limiter watch |
| 1763 | func (f *Fs) openRateLimited(fn func() (io.ReadCloser, error)) (io.ReadCloser, error) { |
| 1764 | var err error |
| 1765 | ctx, cancel := context.WithTimeout(context.Background(), time.Second*10) |
| 1766 | defer cancel() |
| 1767 | start := time.Now() |
| 1768 | |
| 1769 | if err = f.rateLimiter.Wait(ctx); err != nil { |
| 1770 | return nil, err |
| 1771 | } |
| 1772 | |
| 1773 | elapsed := time.Since(start) |
| 1774 | if elapsed > time.Second*2 { |
| 1775 | fs.Debugf(f, "rate limited: %s", elapsed) |
| 1776 | } |
| 1777 | return fn() |
| 1778 | } |
| 1779 | |
| 1780 | // CleanUpCache will cleanup only the cache data that is expired |
| 1781 | func (f *Fs) CleanUpCache(ignoreLastTs bool) { |