Agenda: job state / job progress

Created on 9 Jul 2016  路  3Comments  路  Source: agenda/agenda

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

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:

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.

All 3 comments

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.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

weeco picture weeco  路  4Comments

ephigabay picture ephigabay  路  5Comments

ruslanjur picture ruslanjur  路  4Comments

bankzxcv picture bankzxcv  路  3Comments

nhan-pt picture nhan-pt  路  4Comments