How would I implement a random jitter for randomly scheduled jobs? #2227
-
I have a job that I'm creating in my ASP.NET service that runs some internal archiving task:
I would like to be able to run this job with a random jitter in the schedule, perhaps as wide as 10 minutes around the regular interval. This is because I have multiple copies of this service running and would like to ensure the job gets done, but do not want all of the copies running the job at the same time. I didn't notice a capability for this on any of the default schedules ( |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
For random jitter it's easiest to add a sleep (Task.Delay) in start of your job. This of course means that But your real problem might be that you should run database-backed job store that ensures that multiple instances of job are handled correctly - you can add |
Beta Was this translation helpful? Give feedback.
For random jitter it's easiest to add a sleep (Task.Delay) in start of your job. This of course means that
max_jitter + max_job_execution_time < trigger_interval
must be true so that overlapping/queuing won't happen.But your real problem might be that you should run database-backed job store that ensures that multiple instances of job are handled correctly - you can add
DisallowConcurrentExecution
attribute and cluster will obey that. Remember that concurrent execution checks are based on job keys.