Lets say I have a job scheduled using @agenda/agenda like this
agenda.schedule('tomorrow at noon', 'printAnalyticsReport', {userCount: 100});
I wonder what will happen if my server/node script os down?
- Is agenda is able to restart the past job on next server restart?
- If not, how can I achieve the same?
Yes and no. Agenda should pick your jobs if it was shutdown
gracefuly
.What that means is that if all goes well the actual jobs
lockedAt
field would not be set (will benull
) which should expose your stale jobs for pickup.However if there was NOT a graceful shutdown then they will be skipped since as far as agenda is concerned they are still running.
In situations like this where jobs are in
limbo
mode the UI tool for agenda is extremely helpful. It shows you all the jobs running and gives you a very good overview of what is happening so after a restart you can always review and address any issues.Another approach would be to run a script the unlock all locked jobs on server start:
Or a little more precise way to achieve the same result with this method.
Or another somewhat clean way to do this can be found here.
Here is more on the Agenda stop