Dynamically create jobs #1537
Replies: 1 comment
-
I eventually solved this couple of months ago and I am posting it here for reference. The main server will schedule jobs as follows const agenda = new Agenda({
db: {
address: process.env.MONGO_DB_AGENDA_URI
}
})
agenda.schedule("2024-03-03", ['sendEmail'], { ...data }) And the worker pod will have job definitions as follows const agenda = new Agenda({
db: { address: MONGO_DB_AGENDA_URI, collection: undefined },
ensureIndex: true,
defaultLockLifetime: 1000 * 60 * 3 // 3 minutes
});
agenda.define("sendEmail", async (job, done) => { // your job definition }) The worker pod does not define when these jobs should run rather the server will schedule a job and the worker pod will pick it up since they share a common MongoDB collection. |
Beta Was this translation helpful? Give feedback.
-
How can I dynamically create persistent jobs? For example, consider the following scenario
sendEmail
purge
Is this possible?
If not, then can I create jobs in one server (mongo backed) and expect agenda, which is running on another server, to automatically pick it up?
Beta Was this translation helpful? Give feedback.
All reactions