Skip to content

Blocking dequeue during backoff delay. Cancel now pulls from the queue. #42

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 23 additions & 4 deletions utility/httpplus/httpretry.agent.nut
Original file line number Diff line number Diff line change
Expand Up @@ -60,17 +60,31 @@ class HTTPRetry {
local item = _queue[0];
_processing = true;
item.requestobj._sendasyncqueued(function(success, result, retry_delay=0) {
_processing = false;
if (success) {
_processing = false;
_queue.remove(0);
item.callback(result);
return _dequeue();
} else {
imp.wakeup(retry_delay, _dequeue.bindenv(this));
imp.wakeup(retry_delay, function() {
_processing = false;
_dequeue();
}.bindenv(this));
}
}.bindenv(this));
}
}

function _remove(requestobj) {
foreach (k,v in _queue) {
if (v.requestobj == requestobj) {
_queue.remove(k);
return k;
}
}
return null;
}

}


Expand Down Expand Up @@ -120,8 +134,10 @@ class HTTPRetryRequest {
if (result.statuscode == 429 && "x-agent-rate-limited" in result.headers && "retry-after" in result.headers) {
// This is a retryable failure, wait for as long as are told then try again
server.error("Too many outbound HTTP requests. We have been throttled.")
imp.sleep(result.headers["retry-after"].tofloat());
sendasync(oncomplete, longpolldata, longpolltimeout);
_retry = imp.wakeup(result.headers["retry-after"].tofloat(), function() {
_retry = null;
sendasync(oncomplete, longpolldata, longpolltimeout);
}.bindenv(this);
} else {
// This is a success or a reportable failure
oncomplete(result);
Expand Down Expand Up @@ -154,6 +170,9 @@ class HTTPRetryRequest {
// Cancel the http request
_httprequest.cancel();
_httprequest = null;
} else {
// Pull it out of the queue
_parent._remove(this);
}
}

Expand Down