Closed gregorleban closed 8 years ago
Though unshifting back to the top should work it seems a bit sketchy to me. I would probably use this workflow with a mix of async.queue
and async.retry
function handler(task, callback) {
retry({retry-options}, callApiWithTask, function(err, data) {
callback(data);
}
}
let q = queue(handler, 1);
// add task to call first api end point
// add second,
// etc etc.
Not sure exactly what is going wrong your code, it's hard to debug with that pseudo code
I didn't know about the retry. I've implemented it and it works perfectly fine. Thank you for the suggestion!
:tada:
What version of async are you using?
v2.0.1
Which environment did the issue occur in (Node version/browser version)
Node v4.2.4
What did you do? Please include a minimal reproducable case illustrating issue.
I have multiple web services (S1, S2, ...) that I need to call with the same
http.request
s R1, R2, R3, .... Requests have to be processed in the same order as created (first R1, then R2, ...). If one of the web services Sx goes offline, the requests Rx have to wait and then be executed when the web service gets back online.To achieve this functionality I use the async.queue and use concurency = 1. I create a separate queue for each web service. For each web request that I get I create a task for each web service and enqueue it in the appropriate queue. The callback for the queue is called, which calls the web service. If the request is processed ok, I simply call the callback that I guess removes the task from the queue. In case the request timeouts I call
queue.unshift(task)
which puts the task back to the beginning of the queue so that it should be called again, and then again call the callback.The problem I see is that if one web service goes offline, the task in that queue is tried repeatedly, but unfortunately no tasks from the other queues (for web services that are online) are being processed. Is this expected? I would expect that tasks from each queue would be processed independently.
Here is some (pseudo) code that I have:
Thank you in advance for any help!