Hello,
Just wanted to ask if its possible to set progress(or state) for a job.
Something like:
agenda.define('generate statistic', {priority: 'high', concurrency: 10}, function(job, done) {
job.setState('generate');
//generate for the first 100
job.setState('analyze');
//analyze statics
done();
});
or mabye something like setProgress(0.2)
I hope its Ok to ask with an issue.
Greets
Stefan
Hi @stefan0001, I had the same needs and I discovered that inside the definition callback with the job you can add any attributes you want to save on db and take use various usefull job methods like save(). I solved then creating my own update function like in this example:
var update = function (job, state, progress) {
job.attrs.state = state;
job.attrs.progress = progress;
job.save();
}
agenda.define('generate statistic',{}, function (job, done) {
update(job, 'init', 0);
// ... do something...
update(job, 'inProgress', 50);
// ... do something else...
update(job, 'completed', 100);
done();
});
this is only a basic proposal, you will understand that you can use this idea with your preferred logic and needs.
Hi @flaviodelbianco,
Thank you for your response.
There is one problem. When you schedule the job (like repeatEvery(..). Then you only got one job object or? So you can't see the state when 2 running at the same time.
Agenda offers various job events and i think for your use case you could store each job object onto a separate collection. i think the one you want is to listen to the complete event and then store each job run. please refer documentation here https://github.com/rschmukler/agenda#job-queue-events.
Most helpful comment
Hi @stefan0001, I had the same needs and I discovered that inside the definition callback with the job you can add any attributes you want to save on db and take use various usefull job methods like save(). I solved then creating my own update function like in this example:
this is only a basic proposal, you will understand that you can use this idea with your preferred logic and needs.