log requests per account

This commit is contained in:
Andre Medeiros 2022-03-12 14:46:36 -05:00
parent 195bd55426
commit b9389511f6

View file

@ -174,6 +174,7 @@ func (rac *AuthenticatedClient) request(r *Request, rh ResponseHandler, empty in
return nil, ErrRateLimited return nil, ErrRateLimited
} }
rac.logRequest()
bb, rli, err := rac.doRequest(r) bb, rli, err := rac.doRequest(r)
if err != nil && r.retry { if err != nil && r.retry {
@ -182,6 +183,7 @@ func (rac *AuthenticatedClient) request(r *Request, rh ResponseHandler, empty in
time.AfterFunc(backoff, func() { time.AfterFunc(backoff, func() {
_ = rac.statsd.Incr("reddit.api.retries", r.tags, 0.1) _ = rac.statsd.Incr("reddit.api.retries", r.tags, 0.1)
rac.logRequest()
bb, rli, err = rac.doRequest(r) bb, rli, err = rac.doRequest(r)
done <- struct{}{} done <- struct{}{}
}) })
@ -219,6 +221,14 @@ func (rac *AuthenticatedClient) request(r *Request, rh ResponseHandler, empty in
return rh(val), nil return rh(val), nil
} }
func (rac *AuthenticatedClient) logRequest() error {
if rac.redditId == SkipRateLimiting {
return nil
}
return rac.redis.HIncrBy(context.Background(), "reddit:requests", rac.redditId, 1).Err()
}
func (rac *AuthenticatedClient) isRateLimited() bool { func (rac *AuthenticatedClient) isRateLimited() bool {
if rac.redditId == SkipRateLimiting { if rac.redditId == SkipRateLimiting {
return false return false