We left Russia. We are against aggression and war with Ukraine. It is a tragedy for our nations, it is a nightmare

Scheduled jobs to be run in a sequence


What I have.
With Hangfire.MaximumConcurrentExecutions attribute I configured a Job to have only one concurrent execution.
Than I scheduled several jobs
Job1 scheduled for 10:00
Job2 scheduled for 10:10
Job3 scheduled for 10:15
Job4 scheduled for 10:20
Job5 scheduled for 10:25

At 10:00 Job1 is started and lasts ~40min
Jobs 2, 3, 4, 5 are added to the queue and wait for the Job1 to be finished.
After Job1 is finished - other jobs are running but in arbitrary order, for example, Job4, Job2, Job5, Job3.

The question is: can I make hangfire to respect order in witch my jobs were scheduled and run them respectively Job2, Job3, Job4, Job5 and not randomly? Can Hangfire.Throttling help me with this task?


Schedule Job1. At the end of Job1, queue Job2. At the end of Job2 queue Job 3, etc. You can also just queue Job2, use that job Id to ContinueWith Job3. Then use that job Id to ContinueWith Job4, etc.

Thanks for reply

Those jobs are scheduled automatically like every day at that mentioned time.
Also they are not depend on any other another. So I cannot couple them with ContinueWith or with BatchJob.

Maybe there is another possibility to do so without creating a batch of jobs?
Is there any configuration option I can use? Or some attribute on a job?


They are dependent on each other if you are requiring one to run after the other. My point is to only schedule the first job and have the first job queue the remaining jobs. This ensures that the jobs run one after the other, in the order desired and one at a time.

You should see recurring jobs or scheduled jobs more as “not on the queue until X date/time.” Once that time has passed it is available on the queue. It is not guaranteed to run in FIFO order. Recurring and scheduled jobs aren’t sent immediately for processing, just added to the queue like BackgroundJob.Queue(…).

Batching won’t ensure they’re run in a specific order.