mirror of
https://github.com/christianselig/apollo-backend
synced 2024-11-10 22:17:44 +00:00
log requests per account
This commit is contained in:
parent
195bd55426
commit
b9389511f6
1 changed files with 10 additions and 0 deletions
|
@ -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
|
||||||
|
|
Loading…
Reference in a new issue