Search code examples
c#asp.netquartz.net

Quartz.net - How to skip the next CRON execution if current is still running


For example, I have a task that runs every 1 minute and starts at 8:00, it will be executed at 8:01, 8:02, 8:03, etc. But when the execution at 8:01 execute over 1min -- for example 61 seconds -- how to skip the next execution which is at 8:02 and wait for 8:03?

I had tried to use the DisallowConcurrentExecution attribute, but it just makes the next execution wait for the current and will execute immediately when the current finish.


Solution

  • One option is to create a lock flag/file or something similar that allows you to indicate when the task started running and when it ended. You could then remove the DisallowConcurrentExecution so that the next iteration can go ahead and fire without waiting for the first one. Then you simply check the lock flag on each iteration to see if another instance is still running and simply exit without doing work if the past job is still running. When the execution is complete you delete/disable the lock flag/file.