I have a list of recurring jobs in Hangfire, all with an interval of 20 minutes.
They all call the same method, but with different parameters. eg.
Job id test_1 => MyTestMethod (1)
Job id test_50 => MyTestMethod (50)
Job id test_37 => MyTestMethod (37)
Sometimes a task may take longer than its interval, that is, more than 20 minutes, and I want to make sure that the task does not start again while another instance is already running.
DisableConcurrentExecutionAttribute is not suitable here, because the CAN method can be executed simultaneously, just not with the same parameters.
I tried to set a static Dictionary<string, DateTime> , which kept track of whether the task was already running so that it could block simultaneous method calls, but the problem is that if the application restarts for some reason, it "forgets" which tasks (Hangfire, of course, will continue to run in the background)
UPDATE
I also tried adding the JobState table to my database to keep track of which jobs are running and then checking this table when MyTestMethod starts, but it depends on the setting MyTestMethod running = 1 when it starts and works = 0 when it ends, and if the flow falls halfway through this task (for some reason), which may not happen, thereby preventing the task from being repeated.
I'm sure I can solve this by simply requesting the status of the Hangfire job by job ID - I just canโt find how to do this?