how to send data from job?
need like generic progress method which accept data, not just numbers
any ideas?
needs to be implemented, we do not have support for this currently, but it should be relative easy to do.
any timeline when be available?
If this is about result, then I think there is already a way available, but just needs to be simplified in some way. I searched so that I don't make a duplicate issue.
Other than the following, I tried to job.update but it failed to update the data from within the worker child process.
Way 1
We can listen to global:completed event.
queue.on("global:completed", function(jobID, result) {
console.log(`job ${jobID} completed`, result);
});
The leading result,
job 8298 completed {"data":{"foo":"Tue, 22 May 2018 23:27:40 GMT"},"startTime":"Tue, 22 May 2018 23:27:40 GMT","endTime":"Tue, 22 May 2018 23:27:41 GMT"}
Way 2
We can listen to the finished() event.
const jobPromise = delayQueue.add({ foo: new Date().toUTCString() });
jobPromise.then(jobObject => {
jobObject.finished().then(result => {
console.log({ result });
});
});
which can be more simplified with async await,
async function addJob(data) {
const jobPromise = await delayQueue.add(data);
const result = await jobPromise.finished();
return result;
}
There is just one thing wrong with this, which is, it will throw a Event Listener warning probably due to the finished() promises if you add too many tasks at same time,
MaxListenersExceededWarning: Possible EventEmitter memory leak detected. 11 error listeners added. Use emitter.setMaxListeners() to increase limit
Way 3
I wanted to apply this in some api, so there was a third way which I tried first, Save the data to some redis key.
var redis = require("redis");
var client = redis.createClient(); //creates a new client
client.set('my test key', 'my test value');
If you want to create a message broker, then this is not idea solution for you. All of these wouldn't be required if I could just use bull as a message broker with ack and callbacks :D . But we gotta deal with it with some workaround until someone does the pr. :)
Here is a sample repo for the code above, https://github.com/entrptaher/bull-queue-test
@entrptaher thanks for your samples, but i need data while processing, not final result
@hbakhtiyor in that case you can use way 3 for simple key value data storing. Or we can create a functionality similar to https://github.com/smrchy/rsmq, https://github.com/squaremo/amqp.node etc message brokers.
i think like job progress of kue
job.progress(completed, total [, data])
I was thinking exactly the same; very useful