dylanjha
dylanjha

Reputation: 2523

Agenda (node) create unique job without over-riding the scheduled time

not sure if there is a way to do this with node's agenda library

const data = {userId: 'user-1'}
// this code gets run at 12:00
agenda.create('update-user-record', data)
 .unique({'data.userId': data.userId})
 .schedule('in 30 minutes')
 .save()
// job correctly gets scheduled  at 12:30

// in 5 minutes this code gets run:
agenda.create('update-user-record', data)
 .unique({'data.userId': data.userId})
 .schedule('in 30 minutes')
 .save()

// job stays the same but gets re-scheduled to happen at 12:35

Is there any way to do the above, without overriding the original scheduled time? (in this example - keep the job scheduled at 12:30)

reference: https://github.com/rschmukler/agenda, I couldn't find a way to do this with the api.

Upvotes: 1

Views: 1797

Answers (1)

Matthias
Matthias

Reputation: 808

Based on the documentation and the source code, I would think you can use .unique({'data.userId': data.userId}, { insertOnly: true }) since this uses mongo's $setOnInsert

Upvotes: 1

Related Questions