bull icon indicating copy to clipboard operation
bull copied to clipboard

how to send data from job?

Open hbakhtiyor opened this issue 7 years ago • 8 comments

need like generic progress method which accept data, not just numbers

hbakhtiyor avatar May 13 '18 07:05 hbakhtiyor

i think like job progress of kue

job.progress(completed, total [, data])

hbakhtiyor avatar May 13 '18 17:05 hbakhtiyor

any ideas?

hbakhtiyor avatar May 14 '18 13:05 hbakhtiyor

needs to be implemented, we do not have support for this currently, but it should be relative easy to do.

manast avatar May 14 '18 15:05 manast

any timeline when be available?

hbakhtiyor avatar May 15 '18 14:05 hbakhtiyor

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 avatar May 22 '18 23:05 entrptaher

@entrptaher thanks for your samples, but i need data while processing, not final result

hbakhtiyor avatar May 23 '18 03:05 hbakhtiyor

@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.

entrptaher avatar May 23 '18 19:05 entrptaher

i think like job progress of kue

job.progress(completed, total [, data])

I was thinking exactly the same; very useful

alolis avatar Sep 27 '18 16:09 alolis