BLO: using PUT in async queue to connect to external API

Hello rapid m2m community,

In my BLO application, the hist and config data are accessed via subcribe and processed into a task and pushed into a asyc queue of an object, let it named device.
The tasks should be pushed directly to an external API. To do this, they are pushed into further async queue which is called uplink. This uplink should execute the PUT to forward the tasks to the external API.
Here are some code snippets:

const externalApi = BAPI.createClient(externalApiOpts);

const uplink = async.queue((task, onTaskDone) => {
externalApi.put([task.endpoint, task.noltacode], task.data);
}, UPLINK_CONCURRENCY);

device.queue.push ({uid: sid, endpoint: hist, data: histobject, noltacode: noltaDev.site.name});
device.queue.push ({
uid: sid, endpoint: config, data: data, noltacode: noltaDev.site.name});

Unfortunately, this procedure does not work as desired using PUT in the uplink queue.
Is there a good practice or code sample to perform such PUT tasks.
Best regards,
Marcel

your code does not invoke the onTaskDone callback.

since the externalApi.put supports ES6 async calls, it may help to modify your code as below:

const uplink = async.queue( async(task) => {
    const replyData= await externalApi.put([task.endpoint, task.noltacode], task.data);
     return replyData;
}, UPLINK_CONCURRENCY);

note: the async lib seems to adapt it’s calling behaviour depending on the worker method given. it skips the done-callback as soon as the worker is declared as async function.

if you prefer to stay with old school callbacks, you should add these modifications:

const uplink = async.queue((task, onTaskDone) => {
    externalApi.put([task.endpoint, task.noltacode], task.data)
        .then( replyData => onTaskDone( null, replyData))
        .catch( onTaskDone);
}, UPLINK_CONCURRENCY);

Hi aai,
thank you very much for your assistance.
I will test the code in my application the next days.
Have a nice weekend and best regards.
Marcel