Search code examples
asp.netasp.net-corequartz.nethangfire

Quartz.NET Manually invoked recurring job


I have ASP.NET Core application and I'm using Quartz.NET for reccuring job which ran my TestMethod() every 60 seconds and it works fine.

I need to run this job sometime manually. How to force Quartz.NET to make next reccuring calling 60 seconds after the manual run?

This is what I need to accomplish:

00:01:00 -> Automatic run of TestMethod();
00:02:00 -> Automatic run of TestMethod();
00:02:10 -> Manual run of TestMethod();
00:03:10 -> Automatic run of TestMethod(); (Note: 60 seconds after last run)
...

Maybe is it possible by the Hangfire library?


Solution

  • I guess you can't do that using Quartz or Hangfire. Schedule-based jobs are not affected by manual runs usually. You may also notice that schedule-based jobs do not take into account the execution time, so it may lead to the situation then you have one job still in progress (from the previous run) and another one started by schedule.

    Instead of using simple recurring jobs you can use the following pattern:

    1. Schedule a single execution of your job
    2. Re-schedule completed job at the end of the execution.

    It will help you to avoid the situation described above and also it will allow you to schedule next run after manual trigger.