How to set ID to shedule job #782
-
How could i set ID to schedule job so that i could cancel the execution later in case needed? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
Since the job only exists in the server's memory while running, the easiest way is to keep the variable reference to the 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 |
Beta Was this translation helpful? Give feedback.
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…