public static void ConfigurationHangfire(this IServiceCollection services, IConfiguration Configuration, IGlobalConfiguration globalConfiguration) { var serverProvider = services.BuildServiceProvider(); var hangfireSettings = serverProvider.GetService <IOptions <HangfireSettings> >().Value; var httpJobOptions = serverProvider.GetService <IOptions <HangfireHttpJobOptions> >().Value; var sqlConnectStr = Configuration.GetSection(HangfireConnectStringKey).Get <string>(); var options = new RedisStorageOptions { Prefix = hangfireSettings.TablePrefix, SucceededListSize = 9999, DeletedListSize = 4999, }; var redis = ConnectionMultiplexer.Connect(sqlConnectStr); globalConfiguration.UseRedisStorage(redis, options) .UseConsole(new ConsoleOptions { BackgroundColor = "#000079" }) .UseTagsWithRedis(new TagsOptions() { TagsListStyle = TagsListStyle.Dropdown }) .UseHangfireHttpJob(httpJobOptions) .UseHeartbeatPage(); }
public void Configure(IGlobalConfiguration hangfireGlobalConfiguration) { var configuration = global::Apexnet.JobQueue.Configuration.RedisStorage.Instance; var options = ConfigureHangfireRedisStorageOptions(configuration.RedisStorageOptions); hangfireGlobalConfiguration.UseRedisStorage(configuration.ConnectionString, options); }
public static void ConfigurationHangfire(this IServiceCollection services, IConfiguration configuration, IGlobalConfiguration globalConfiguration) { var serverProvider = services.BuildServiceProvider(); var langStr = configuration.GetSection(HangfireLangKey).Get <string>(); var envLangStr = GetEnvConfig <string>("Lang"); if (!string.IsNullOrEmpty(envLangStr)) { langStr = envLangStr; } if (!string.IsNullOrEmpty(langStr)) { System.Threading.Thread.CurrentThread.CurrentUICulture = new System.Globalization.CultureInfo(langStr); } var hangfireSettings = serverProvider.GetService <IOptions <HangfireSettings> >().Value; ConfigFromEnv(hangfireSettings); var httpJobOptions = serverProvider.GetService <IOptions <HangfireHttpJobOptions> >().Value; ConfigFromEnv(httpJobOptions); httpJobOptions.GlobalSettingJsonFilePath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory !, "hangfire", "hangfire_global.json"); var sqlConnectStr = configuration.GetSection(HangfireConnectStringKey).Get <string>(); var envSqlConnectStr = GetEnvConfig <string>("HangfireRedisConnectionString"); if (!string.IsNullOrEmpty(envSqlConnectStr)) { sqlConnectStr = envSqlConnectStr; } var options = new RedisStorageOptions { Prefix = hangfireSettings.TablePrefix, SucceededListSize = 9999, DeletedListSize = 4999, UseTransactions = false }; var redis = ConnectionMultiplexer.Connect(sqlConnectStr); globalConfiguration.UseRedisStorage(redis, options) .UseConsole(new ConsoleOptions { BackgroundColor = "#000079" }) .UseTagsWithRedis(new TagsOptions() { TagsListStyle = TagsListStyle.Dropdown }, options) .UseHangfireHttpJob(httpJobOptions) .UseHeartbeatPage(); }
private void Configuration(IGlobalConfiguration globalConfiguration) { var redis = ConnectionMultiplexer.Connect(JsonConfig.GetSection("HangfireRedisConnectionString") .Get <string>()); var options = new RedisStorageOptions { Prefix = "hangfire:", SucceededListSize = 9999, DeletedListSize = 4999, Db = redis.GetDatabase().Database }; globalConfiguration.UseRedisStorage(redis, options) .UseConsole(new ConsoleOptions() { BackgroundColor = "#000079" }) .UseHangfireHttpJob(new HangfireHttpJobOptions { MailOption = new MailOption { Server = JsonConfig.GetSection("HangfireMail:Server").Get <string>(), Port = JsonConfig.GetSection("HangfireMail:Port").Get <int>(), UseSsl = JsonConfig.GetSection("HangfireMail:UseSsl").Get <bool>(), User = JsonConfig.GetSection("HangfireMail:User").Get <string>(), Password = JsonConfig.GetSection("HangfireMail:Password").Get <string>(), }, DefaultRecurringQueueName = JsonConfig.GetSection("DefaultRecurringQueueName").Get <string>(), DefaultBackGroundJobQueueName = "DEFAULT", DefaultTimeZone = "Asia/Shanghai", //EnableDingTalk = true, //CurrentDomain = "http://localhost:5000" //RecurringJobTimeZone = TimeZoneInfo.Local, // CheckHttpResponseStatusCode = code => (int)code < 400 //===》(default) //AddHttpJobFilter = (jobContent) => //{ // //添加httpjob的拦截器 如果返回false就代表不添加 返回true则真正的添加 // if (jobContent.Url.StartsWith("http://localhost") || // jobContent.Url.StartsWith("http://127.0.0.1")) // { // return true; // } // return false; //} }).UseTagsWithRedis(redis, redisOptions: options); }