示例#1
0
 private void Configuration(IGlobalConfiguration globalConfiguration)
 {
     globalConfiguration
     .UseSqlServerStorage(JsonConfig.GetSection("HangfireSqlserverConnectionString").Get <string>(), new SqlServerStorageOptions
     {
         CommandBatchMaxTimeout       = TimeSpan.FromMinutes(5),
         SlidingInvisibilityTimeout   = TimeSpan.FromMinutes(5),
         QueuePollInterval            = TimeSpan.Zero,
         UseRecommendedIsolationLevel = true,
         UsePageLocksOnDequeue        = true,
         DisableGlobalLocks           = true
     })
     .UseTagsWithSql()
     .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"
     });
 }
        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 mssqlOption = new SqlServerStorageOptions
            {
                CommandBatchMaxTimeout       = TimeSpan.FromMinutes(5),
                SlidingInvisibilityTimeout   = TimeSpan.FromMinutes(5),
                QueuePollInterval            = TimeSpan.Zero,
                UseRecommendedIsolationLevel = true,
                UsePageLocksOnDequeue        = true,
                DisableGlobalLocks           = true
            };

            globalConfiguration.UseSqlServerStorage(sqlConnectStr, mssqlOption)
            .UseConsole(new ConsoleOptions
            {
                BackgroundColor = "#000079"
            })
            .UseTagsWithSql(new TagsOptions()
            {
                TagsListStyle = TagsListStyle.Dropdown
            })
            .UseHangfireHttpJob(httpJobOptions)
            .UseHeartbeatPage();
        }
示例#3
0
 private void Configuration(IGlobalConfiguration globalConfiguration)
 {
     globalConfiguration
     .UseSqlServerStorage(JsonConfig.GetSection("HangfireSqlserverConnectionString").Get <string>(), new SqlServerStorageOptions
     {
         CommandBatchMaxTimeout       = TimeSpan.FromMinutes(5),
         SlidingInvisibilityTimeout   = TimeSpan.FromMinutes(5),
         QueuePollInterval            = TimeSpan.Zero,
         UseRecommendedIsolationLevel = true,
         UsePageLocksOnDequeue        = true,
         DisableGlobalLocks           = true
     })
     .UseTagsWithSql()
     .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",
         RecurringJobTimeZone          = TZConvert.GetTimeZoneInfo("Asia/Shanghai"), //这里指定了添加周期性job时的时区
         // RecurringJobTimeZone = TimeZoneInfo.Local
         // CheckHttpResponseStatusCode = code => (int)code < 400   //===》(default)
     });
 }
示例#4
0
        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>("HangfireSqlserverConnectionString");

            if (!string.IsNullOrEmpty(envSqlConnectStr))
            {
                sqlConnectStr = envSqlConnectStr;
            }

            var mssqlOption = new SqlServerStorageOptions
            {
                CommandBatchMaxTimeout       = TimeSpan.FromMinutes(5),
                SlidingInvisibilityTimeout   = TimeSpan.FromMinutes(5),
                QueuePollInterval            = TimeSpan.Zero,
                UseRecommendedIsolationLevel = true,
                UsePageLocksOnDequeue        = true,
                DisableGlobalLocks           = true
            };

            globalConfiguration.UseSqlServerStorage(sqlConnectStr, mssqlOption)
            .UseConsole(new ConsoleOptions
            {
                BackgroundColor = "#000079"
            })
            .UseTagsWithSql(new TagsOptions()
            {
                TagsListStyle = TagsListStyle.Dropdown
            })
            .UseHangfireHttpJob(httpJobOptions)
            .UseHeartbeatPage();
        }
示例#5
0
        /// <summary>
        /// This method is called during the apply method
        /// </summary>
        protected override void ProviderSetup(IGlobalConfiguration hangfireConfiguration)
        {
            if (!Enabled)
            {
                return;
            }

            hangfireConfiguration.UseSqlServerStorage(SqlConnectionString);
            IsActive = true;
        }
示例#6
0
        internal static IGlobalConfiguration ConfigSqlServer(this IGlobalConfiguration configuration, string dbConn)
        {
            configuration.UseSqlServerStorage(dbConn, new SqlServerStorageOptions
            {
                CommandBatchMaxTimeout       = TimeSpan.FromMinutes(5),
                SlidingInvisibilityTimeout   = TimeSpan.FromMinutes(5),
                QueuePollInterval            = TimeSpan.Zero,
                UseRecommendedIsolationLevel = true,
                DisableGlobalLocks           = true
            });

            return(configuration);
        }
示例#7
0
 public void Configuration(IGlobalConfiguration globalConfiguration)
 {
     globalConfiguration.UseSqlServerStorage("connect string").UseHangfireHttpJob();
 }