ARTICLE AD BOX
I have got the Cron expression for a recurring job in appsettings.json:
{ "HangfireSettings": { "DailyJobCron": "0 0 * * *" } }I have configured Hangfire in an extension method of Program.cs as follows:
public static class HangfireConfiguration { public static IServiceCollection AddHangfireConfiguration( this IServiceCollection services, IConfiguration configuration ) { services.AddHangfire(config => config .SetDataCompatibilityLevel(CompatibilityLevel.Version_180) .UseSimpleAssemblyNameTypeSerializer() .UseRecommendedSerializerSettings() .UseSqlServerStorage( configuration.GetConnectionString("DefaultConnection"), new SqlServerStorageOptions { CommandBatchMaxTimeout = TimeSpan.FromMinutes(5), SlidingInvisibilityTimeout = TimeSpan.FromMinutes(5), QueuePollInterval = TimeSpan.Zero, UseRecommendedIsolationLevel = true, DisableGlobalLocks = true, } ) ); services.AddHangfireServer(x => { x.ServerName = "Server3"; x.Queues = new[] { "daily-queue" }; x.WorkerCount = 20; }); return services; } }This is the method that I want to schedule in the recurring job:
public class HangfireJob : IHangfireJob { [Queue("daily-queue")] public void DailyJob(string message) { Console.WriteLine($"[{DateTime.Now}] [Server 3]: {message}"); } }Now I want to configure a recurring job which will be scheduled during startup of the application that runs daily at 12:00 AM. I should be able to change the time at which it runs by updating the Cron expression from appsettings, so that the change is reflected automatically on the queue in the database without the need to rerun the application. What would be the best way to do this, like where and how should I add the RecurringJobManager? TIA
