I’m using:
Hangfire.AspNetCore
Hangfire.Autofac
FaceIT.Hangfire.Tags.Redis.StackExchange
I have some long-running, resource-intensive tasks. Therefore, I need to:
Dynamically adjust the WorkerCount
based on system load.
Stop or pause certain jobs in emergency situations.
Is there an official way to achieve this with Hangfire?
I would be really happy to hear from you guys.
A list of the jobs can be retrieved with the JobStorage.Current.GetMonitoringApi()
. They can be deleted, but you probably need to add CancellationToken to the method, otherwise the job will be deleted from the queue, but the method will continue running.
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.
public void InitializeJobs()
{
const string myRecurringJobId = "Ftmch-20";
_recurringJobManager.AddOrUpdate(
myRecurringJobId,
Job.FromExpression<MyJob>(j => j.LongRunningJob(null, CancellationToken.None)),
"0/10 * * * * *");
}
…
public class My…