public static IApplicationBuilder ConfigureHangfire(this IApplicationBuilder app, IConfiguration configuration) { // Grab EnvironmentSettings var environmentSettings = new EnvironmentSettings(); configuration.GetSection("EnvironmentSettings").Bind(environmentSettings); // Enable basic auth only for Staging/Production app.ConfigureSharedHangfire(environmentSettings.EnvironmentName == "Staging" || environmentSettings.EnvironmentName == "Production"); // Grab AppSettings var appSettings = new Application.Settings.AppSettings(); configuration.GetSection("AppSettings").Bind(appSettings); // Background jobs var jobsIntervalInMinutes = appSettings.JobsIntervalInMinutes; RecurringJob.AddOrUpdate <MainJob>("Main", x => x.Run(), $"*/{jobsIntervalInMinutes} * * * *"); //RecurringJob.AddOrUpdate<SendWhatsappNotificationsJob>("Send whatsapp notifications", x => x.Run(), $"*/{jobsIntervalInMinutes} * * * *"); //RecurringJob.AddOrUpdate<SendTelgramNotificationsJob>("Send telegram notifications", x => x.Run(), $"*/{jobsIntervalInMinutes} * * * *"); //RecurringJob.AddOrUpdate<RemoveObsoleteLinesJob>("Remove obsolete lines", x => x.Run(), $"*/{jobsIntervalInMinutes} * * * *"); return(app); }
public static IServiceCollection ConfigureHangfire(this IServiceCollection services, IConfiguration configuration) { services.ConfigureSharedHangfire(); // Grab AppSettings var appSettings = new Application.Settings.AppSettings(); configuration.GetSection("AppSettings").Bind(appSettings); // Grab EnvironmentSettings var environmentSettings = new EnvironmentSettings(); configuration.GetSection("EnvironmentSettings").Bind(environmentSettings); if (appSettings.UseMemoryStorage) { services.AddHangfire(x => x.UseMemoryStorage()); } else { services.AddHangfire(x => x.UseSqlServerStorage(configuration.GetConnectionString("CryptoWatcher"), new SqlServerStorageOptions { PrepareSchemaIfNecessary = environmentSettings.EnvironmentName == "Development" })); } // Return return(services); }