Skip to content

How to set ID to shedule job #782

Answered by sheerlox
airnoteapps asked this question in Q&A
Discussion options

You must be logged in to vote

Since the job only exists in the server's memory while running, the easiest way is to keep the variable reference to the CronJob object if you need to call the .stop() method on it later.
A good way of doing this across your application without having to pass the variable around would be to implement a jobs manager, which would keep an in-memory store of type Map<string, CronJob> and provide a method to stop and remove a specific job.

Remember that restarting your server will always destroy all the jobs currently running, so if you need them to be restarted along with the server, you'd also need to store basic job information (the parameters you pass to CronJob) in a persistence layer and…

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by sheerlox
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants