Reputation: 3495
I am using Hangfire
in my .Net Core application to perform background processing. There are some scenario where I need to Quit or Stop the job execution. For that I have searched and found that I can use BackgroundJob.Delete(jobId);
OR RecurringJob.RemoveIfExists(jobId);
to Stop the Job, It works fine But, at the same It also marked job as deleted so the issue is when the application pool starts again at that time that Job will not execute.
So is there any way to quit the job without delete it?
Any help would be highly appreciated !
Thanks,
Upvotes: 4
Views: 5391
Reputation: 1
You can specify the cron expression as never.
According to Hangfire documentation
//
// Summary:
// Returns cron expression that never fires. Specifically 31st of February
public static string Never()
{
return Yearly(2, 31);
}
Example:
using Hangfire;
RecurringJob.AddOrUpdate<IScheduledJobService>("some-id", x => x.SomeMethodToInvokeAJob(), Cron.Never());
Note: The IScheduledJobService is a customized service for managing the actual logic of the jobs.
Upvotes: 0