Hangfire
Hangfire copied to clipboard
Not launching a scheduled job if the previous one didn't complete
Good Morning everyone,
I have a simple use case that I couldn't solve, and I'm sure there should be a way to do it. I have looked into DisableConcurrentExecution, but it seems not doing what I expect. Besides, this I have read that not always works especially with mongo as storage provider.
The case is simple: I have a recurring Job 1 scheduled each X time (let's say 1 day). This job launches thousands of other jobs and sometimes the time it takes to execute all the jobs tree, it is more than 1 day.
What I would like to achieve is that if the Job 1 tree didn't finish, hangfire skips completely the next execution and wait for another time window, or two depending on when the Job 1 finishes. If for example it takes 3 days, the Job 1 scheduled for the second day and third day should be skipped, avoiding creating a perpetual queue, where more and more jobs can be added than the actual process can handle.
Is there a way to do something like this? I'm sure yes Many thanks for the help
Please try a background job filter from this gist – https://gist.github.com/odinserj/a6ad7ba6686076c9b9b2e03fcf6bf74e
Hello @odinserj, this seems doing the trick even it seems jobs are only "parked" and executed when the other execution finishes. Since I'm running long time jobs I'm not sure about this but for now this did the trick. I just needed to changed the serialization functions of your gist because they are marked as obsolete.
Many thanks for now and stay strong with the situation
We this feature as well