In Hangfire, I have successfully set recurring jobs and am able to trigger manually if I want to, thanks to the Web UI and its "trigger" button.
RecurringJob.AddOrUpdate(..);
But I'm willing to set a job that is never fired automatically. Only on demand from the WebUi. Think of it as a set of maintenance task that are triggered only when needed. Manually.
I was thinking of adding a non-reccuring Job in the await state, but was not able to (and it sounds wrong).
Are "On demand only" jobs possible with Hangfire?
Recurring job registration is almost as simple as background job registration – you need to write a single line of code, but you also need to specify an identifier you can use to refer to your job later. The call to AddOrUpdate method will create a new recurring job or update existing job with the same identifier.
You would use a similar method if you'd like to stop the job prematurely via user interaction. When the user requests it to stop, you set a value in your database (or wherever you want to store the Stop Request). Each iteration of your job would check that value, and if it indicates a Stop Request, then exit the loop.
The idea is, on a loading page, there is an email input field. Once the user writes his email and clicks the Get Email button, a background job should trigger. It will check if the transaction is complete, and once it is, it will send an email to the user.
I used this (hangfire 1.7 on .net 4.6.2)
RecurringJob.AddOrUpdate(() => ..., "0 0 31 2 0");
It shows up in the dashboard as:
Next execution N/A
I use this CRON expression as Never: 0 0 29 2/12000 WED At midnight, on a 29th of Feb that happens to be a Wednesday, every century.
As @youen found out, this expression yields a later date. "0 0 29 2/12000 MON"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With