Agenda: Schedule same task with different data

Created on 11 Sep 2016  路  3Comments  路  Source: agenda/agenda

I am getting trouble in scheduling same task with different data sets as it is been treated same and updates the already present task in the db with same task name.

task: notify-user-about-appointment

Example:

 var jobDate = new Date(); 
 var jobData = {to: '[email protected]'}; 
 agenda.schedule(jobDate, 'notify-user-about-appointment', jobData);

on second instance with data

var jobData = {to: '[email protected]'}; 

It overwrites the previously created entry in the database.

  • Does the job name has to be unique?
  • Is there any workaround?

Most helpful comment

I faced the same problem and after some digging and testing the solution is:

  • Do not use "agenda.every", it really creates the job of type "single" where second instance overwrites the first. However when I ran my whole agenda script few times over, sometimes it created 2 jobs out of 3 in the Mongo (I wanted all 3). Using callback hell corrected the "problem" and agenda created only 1 job at all times.

  • You should use (for job scheduled every 10 minutes between 8:30 - 12:00 on weekdays)
    var job = agenda.create('jobName'); job.repeatEvery('30,40,50 8 * * 1-5').save(); job.repeatEvery('*/10 9-12 * * 1-5').save();
    This creates 2 instances with different schedules correctly (with type : "normal").

For once you can close this task.

All 3 comments

This is not the documented behavior and this is not the behavior I'm seeing:

In this example, two jobs get correctly scheduled

1__crowdcast__node__node__and_schedule_same_task_with_different_data_ _issue__364_ _rschmukler_agenda

I faced the same problem and after some digging and testing the solution is:

  • Do not use "agenda.every", it really creates the job of type "single" where second instance overwrites the first. However when I ran my whole agenda script few times over, sometimes it created 2 jobs out of 3 in the Mongo (I wanted all 3). Using callback hell corrected the "problem" and agenda created only 1 job at all times.

  • You should use (for job scheduled every 10 minutes between 8:30 - 12:00 on weekdays)
    var job = agenda.create('jobName'); job.repeatEvery('30,40,50 8 * * 1-5').save(); job.repeatEvery('*/10 9-12 * * 1-5').save();
    This creates 2 instances with different schedules correctly (with type : "normal").

For once you can close this task.

Maybe we need a PR to correct that behavior of the every method with jobs with the same name.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

0x62 picture 0x62  路  6Comments

niftylettuce picture niftylettuce  路  6Comments

bankzxcv picture bankzxcv  路  3Comments

stefan0001 picture stefan0001  路  3Comments

ekegodigital picture ekegodigital  路  3Comments