Is there a simple way of stopping a hangfire.io job from enqueuing if one is already enqueued?
Looking at the jobfilterattribute, nothing stands out as how to get the state of anything on the server. Can I use the connection objects and query the store?
Thanks
Each iteration of your job would check that value, and if it indicates a Stop Request, then exit the loop. You can achieve this by using IMonitorinApi and fetch jobs that are processing. Then you can delete them by using IBackgroundJobClient. You need to pass in a cancellationtoken though.
There is no “Cancel” button for jobs in the built-in dashboard, only a “Delete” button. Using that Delete button will remove the Job from the running jobs in the built-in dashboard (near) instantly.
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.
Schedule( () => Console. WriteLine("Hello, world"), TimeSpan. FromDays(1)); Hangfire Server periodically checks the schedule to enqueue scheduled jobs to their queues, allowing workers to execute them.
Have a look at the following gist by the library owner https://gist.github.com/odinserj/a8332a3f486773baa009
This should prevent the same job from being en-queued more than once by querying the fingerprint.
You can activate it per background job by decorating the method with the attribute [DisableMultipleQueuedItemsFilter]
.
Or you can enable it globally GlobalJobFilters.Filters.Add(new DisableMultipleQueuedItemsFilter());
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