Hangfire
Hangfire copied to clipboard
Feature Request: Throw Exception or return False from RecurringJobManager.Trigger(name) when referenced Job does not exist.
I was working with some testing code and the related recurring job I was trying to trigger was not registered via RecurringJob.AddOrUpdate(..) and was surprised that the call to RecurringJobManager.Trigger(name) did not throw or return any indication that there was an issue.
Ideally we'd want to know that the job we're trying to trigger does not even exist. I was expecting some type of an exception to be thrown if that was the case. I see the code for that method it is already doing a 'check' for the job and when not found it just returns.
It would be helpful to return some awareness to the caller that they shouldn't expect their call to actually work. To avoid throwing and the performance implications that has, just returning False would be sufficient. Otherwise, throwing an exception seems appropriate versus a silent failure.
Please check the RecurringJobManager.TriggerExecution method available from version 1.7.29.
So I've switched to using that newer method and it's helped identify an issue we've been chasing for a while. It didn't solve it but gave us a new clue. I'll save that topic for another issue once I've dug into things a bit further.
What I did find though is that while I was chasing that issue I was evaluating how we're triggering the jobs and one key difference I found was that we create a new instance of the RecurringJobManager each time we call our helper method vs when we register the jobs we use RecurringJob and the static methods there.
When I tried to switch to using RecurringJob I found that the original Trigger method was present on it, but the newer TriggerExecution version wasn't. I'm not sure if that would have any impact on my current issue but I was going to point it out and ask if the plan is/was to expose it there as well. I'd much rather leave Hangfire itself to manage the instances of the RecurringJobManager being used but until that method is exposed on RecurringJob I can't do that.
Thanks!
Thanks for noticing that, TriggerExecution method will be added to the static RecurringJob class in version 1.7.31.
RecurringJob.TriggerJob method added instead, will be available in 1.7.31 in few moments.