agenda icon indicating copy to clipboard operation
agenda copied to clipboard

endDate option in the repeatEvery with interval has no effect on Job and job keeps running after the endDate.

Open pnagaswa opened this issue 5 years ago • 5 comments

Here is the code snippet that schedules a repeat test job 'tester'

let time = (ms=0) => new Date(Date.now() + ms*1000);
let options = { endDate: time(84600) }; // next day
let params = {};
let params['message'] = 'Async EndDate';
let params['unique_id'] = 'uniqueJob-10234';

agenda.create("tester", params)
        .unique({ "data.unique_id": params['unique_id'] })
        .repeatEvery('2 minutes', options).save();

Mongo DB has the job with the endDate properly setup but the Job keeps running after the endDate.

{ 
  "_id" : ObjectId("607907eacebe7ea5ee1414d6"), 
  "data" : { "message" : "Async EndDate", "unique_id" : "uniqueJob-10234" }, 
  "name" : "tester", 
  "endDate" : ISODate("2021-04-14T03:14:02.977Z"),
  "lastModifiedBy" : 73599, 
  "nextRunAt" : ISODate("2021-04-15T03:46:03.024Z"), 
  "priority" : 0, 
  "repeatInterval" : "2 minutes", 
  "repeatTimezone" : null, 
  "skipDays" : null, 
  "startDate" : null, 
  "type" : "normal", 
  "lockedAt" : null, 
  "lastRunAt" : ISODate("2021-04-15T03:44:03.024Z"), 
  "lastFinishedAt" : ISODate("2021-04-15T03:44:03.027Z") 
}

As you can for mongo collection, Job keeps running after '2021-04-14' well into '2021-04-15' date.

pnagaswa avatar Apr 16 '21 03:04 pnagaswa

Agenda version : 4.1.2 Node version: v14.15.1 Mongo DB version: 4.4.3

pnagaswa avatar Apr 16 '21 03:04 pnagaswa

+1

rodolfoviolac avatar Sep 25 '21 23:09 rodolfoviolac

+1

gabriel1lima avatar Oct 07 '21 12:10 gabriel1lima

@rodolfoviolac & @gabriel1lima thanks for the votes, but instead of "+1"-ing, please use the reactions (thumbs up or otherwise) to "vote" for issues, and/or subscribe in the sidebar to receive updates.

pdfowler avatar Oct 07 '21 23:10 pdfowler

I have the same issue.

I had to do a workaround where I do check at the start and I've got the end date saved in my data attributes.

if (moment().isAfter(moment(job.attrs.data.endDate))) {
        console.log("job end date is in the past");
        await job.disable();
        return done()
}

syedkhairi avatar Feb 20 '23 18:02 syedkhairi