// todo make overloads to simplify the common case public static IGlobalConfiguration <AzureJobStorage> UseAzureStorage(this IGlobalConfiguration configuration, AzureStorageOptions options) { var storage = new AzureJobStorage(options); return(configuration.UseStorage(storage)); }
private void Configuration(IGlobalConfiguration globalConfiguration) { globalConfiguration.UseStorage( new MySqlStorage( JsonConfig.GetSection("HangfireMysqlConnectionString").Get <string>(), new MySqlStorageOptions { TransactionIsolationLevel = IsolationLevel.ReadCommitted, QueuePollInterval = TimeSpan.FromSeconds(15), JobExpirationCheckInterval = TimeSpan.FromHours(1), CountersAggregateInterval = TimeSpan.FromMinutes(5), PrepareSchemaIfNecessary = true, DashboardJobListLimit = 50000, TransactionTimeout = TimeSpan.FromMinutes(1), TablePrefix = "hangfire" })) .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>() }) .UseTagsWithMysql(); }
public static IGlobalConfiguration <MemoryStorage> UseMemoryStorage(this IGlobalConfiguration configuration, MemoryStorageOptions storageOptions, Data data) { var storage = new MemoryStorage(storageOptions, data); return(configuration.UseStorage(storage)); }
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 mysqlOption = new MySqlStorageOptions { TransactionIsolationLevel = IsolationLevel.ReadCommitted, QueuePollInterval = TimeSpan.FromSeconds(15), JobExpirationCheckInterval = TimeSpan.FromHours(1), CountersAggregateInterval = TimeSpan.FromMinutes(5), PrepareSchemaIfNecessary = true, DashboardJobListLimit = 50000, TransactionTimeout = TimeSpan.FromMinutes(1), TablesPrefix = hangfireSettings.TablePrefix }; globalConfiguration.UseStorage(new MySqlStorage(sqlConnectStr, mysqlOption)) .UseConsole(new ConsoleOptions { BackgroundColor = "#000079" }) .UseHangfireHttpJob(httpJobOptions) .UseTagsWithMySql(new TagsOptions() { TagsListStyle = TagsListStyle.Dropdown }, sqlOptions: mysqlOption) .UseHeartbeatPage(); }
public static IGlobalConfiguration <InMemoryStorage> UseInMemoryStorage(this IGlobalConfiguration configuration) { if (configuration == null) { throw new ArgumentNullException(nameof(configuration)); } return(configuration.UseStorage(new InMemoryStorage())); }
/// <summary> /// 配置使用SqlServer /// </summary> /// <param name="configuration"></param> /// <param name="nameOrConnectionString"></param> /// <returns></returns> public static IGlobalConfiguration <SqlServerStorage> UseSqlServer(this IGlobalConfiguration configuration, string nameOrConnectionString) { Error.ThrowIfNull(configuration, nameof(configuration)); Error.ThrowIfNull(nameOrConnectionString, nameof(nameOrConnectionString)); var storage = new SqlServerStorage(nameOrConnectionString); return(configuration.UseStorage(storage)); }
public static MemoryStorage UseMemoryStorage(this IGlobalConfiguration configuration, MemoryStorageOptions storageOptions) { var storage = new MemoryStorage(storageOptions); configuration.UseStorage(storage); return(storage); }
/// <summary> /// Tells the bootstrapper to use FluentNHibernate provider as a job storage, /// that can be accessed using the given connection string or /// its name. /// </summary> /// <param name="configuration">Configuration</param> /// <param name="nameOrConnectionString">Connection string or its name</param> /// <param name="providerType">Provider type from enumeration</param> /// <param name="options">Advanced options</param> public static FluentNHibernateJobStorage UseFluentNHibernateJobStorage( this IGlobalConfiguration configuration, string nameOrConnectionString, ProviderTypeEnum providerType, FluentNHibernateStorageOptions options = null) { var storage = FluentNHibernateStorageFactory.For(providerType, nameOrConnectionString, options); configuration.UseStorage(storage); return(storage); }
private void Configuration(IGlobalConfiguration globalConfiguration) { var mysqlOption = new MySqlStorageOptions { TransactionIsolationLevel = IsolationLevel.ReadCommitted, QueuePollInterval = TimeSpan.FromSeconds(15), JobExpirationCheckInterval = TimeSpan.FromHours(1), CountersAggregateInterval = TimeSpan.FromMinutes(5), PrepareSchemaIfNecessary = true, DashboardJobListLimit = 50000, TransactionTimeout = TimeSpan.FromMinutes(1), TablesPrefix = "hangfire" }; globalConfiguration.UseStorage( new MySqlStorage( JsonConfig.GetSection("HangfireMysqlConnectionString").Get <string>() , mysqlOption )) .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; //} }) .UseTagsWithMySql(sqlOptions: mysqlOption) .UseHeartbeatPage(); }
public static IGlobalConfiguration <RavenStorage> UseEmbeddedRavenStorage(this IGlobalConfiguration configuration) { configuration.ThrowIfNull("configuration"); Repository.Embedded = true; var storage = new RavenStorage(); return(configuration.UseStorage(storage)); }
/// <summary> /// Tells the bootstrapper to use PostgreSQL as a job storage /// with the given options, that can be accessed using the specified /// connection string or its name. /// </summary> /// <param name="configuration">Configuration</param> /// <param name="nameOrConnectionString">Connection string or its name</param> /// <param name="connectionSetup">Optional setup action to apply to created connections</param> /// <param name="options">Advanced options</param> public static IGlobalConfiguration <PostgreSqlStorage> UsePostgreSqlStorage( this IGlobalConfiguration configuration, string nameOrConnectionString, Action <NpgsqlConnection> connectionSetup, PostgreSqlStorageOptions options) { var storage = new PostgreSqlStorage(nameOrConnectionString, connectionSetup, options); return(configuration.UseStorage(storage)); }
/// <summary> /// 启用基于CSRedisCore实现的Redis存储 /// </summary> /// <param name="configuration">Hangfire全局配置</param> public static IGlobalConfiguration <RedisStorage> UseRedisStorage([NotNull] this IGlobalConfiguration configuration) { if (configuration == null) { throw new ArgumentNullException(nameof(configuration)); } var storage = new RedisStorage(); return(configuration.UseStorage(storage)); }
/// <summary> /// Configure Hangfire to use MongoDB storage /// </summary> /// <param name="configuration">Configuration</param> /// <param name="connectionString">Connection string for Mongo database, for example 'mongodb://*****:*****@host:port'</param> /// <param name="databaseName">Name of database at Mongo server</param> /// <returns></returns> public static MongoStorage UseMongoStorage(this IGlobalConfiguration configuration, string connectionString, string databaseName) { MongoStorage storage = new MongoStorage(connectionString, databaseName, new MongoStorageOptions()); configuration.UseStorage(storage); return(storage); }
/// <summary> /// Configure Hangfire to use MongoDB storage /// </summary> /// <param name="configuration">Configuration</param> /// <param name="mongoClientSettings">Client settings for Mongo</param> /// <param name="databaseName">Name of database at Mongo server</param> /// <returns></returns> public static MongoStorage UseMongoStorage(this IGlobalConfiguration configuration, MongoClientSettings mongoClientSettings, string databaseName) { var storage = new MongoStorage(mongoClientSettings, databaseName, new MongoStorageOptions()); configuration.UseStorage(storage); return(storage); }
/// <summary> /// Tells the bootstrapper to use PostgreSQL as a job storage, /// that can be accessed using the given connection string or /// its name. /// </summary> /// <param name="configuration">Configuration</param> /// <param name="nameOrConnectionString">Connection string or its name</param> public static PostgreSqlStorage UsePostgreSqlStorage( this IGlobalConfiguration configuration, string nameOrConnectionString) { var storage = new PostgreSqlStorage(nameOrConnectionString); configuration.UseStorage(storage); return(storage); }
/// <summary> /// Configure Hangfire to use LiteDB storage /// </summary> /// <param name="configuration">Configuration</param> /// <param name="connectionString">Connection string for LiteDB database, for example 'LiteDB://*****:*****@host:port'</param> /// <param name="storageOptions">Storage options</param> /// <returns></returns> public static LiteDbStorage LiteDbStorage(this IGlobalConfiguration configuration, string connectionString, LiteDbStorageOptions storageOptions) { var storage = new LiteDbStorage(connectionString, storageOptions); configuration.UseStorage(storage); return(storage); }
public static IGlobalConfiguration <RavenStorage> UseRavenStorage(this IGlobalConfiguration configuration, string connectionString) { configuration.ThrowIfNull("configuration"); connectionString.ThrowIfNull("connectionString"); Repository.ConnectionString = connectionString; var storage = new RavenStorage(); return(configuration.UseStorage(storage)); }
public static PostgreSqlStorage UsePostgreSqlStorage( this IGlobalConfiguration configuration, string connectionString, PostgreSqlStorageOptions options) { var storage = new PostgreSqlStorage(connectionString, options); configuration.UseStorage(storage); return(storage); }
/// <summary> /// 使用CSRedis 作为hangfire存储 /// </summary> /// <param name="configuration"></param> /// <param name="redisClient"></param> /// <param name="options"></param> /// <returns></returns> public static IGlobalConfiguration <RedisStorage> UseRedisStorage( [NotNull] this IGlobalConfiguration configuration, CSRedis.CSRedisClient redisClient, RedisStorageOptions options = null) { if (configuration == null) { throw new ArgumentNullException(nameof(configuration)); } var storage = new RedisStorage(redisClient, options); return(configuration.UseStorage(storage)); }
/// <summary> /// Configure Hangfire to use MongoDB storage /// </summary> /// <param name="configuration">Configuration</param> /// <param name="mongoClientSettings">Client settings for Mongo</param> /// <param name="databaseName">Name of database at Mongo server</param> /// <param name="options">Storage options</param> /// <returns></returns> public static MongoStorage UseMongoStorage(this IGlobalConfiguration configuration, MongoClientSettings mongoClientSettings, string databaseName, MongoStorageOptions options) { MongoStorage storage = new MongoStorage(mongoClientSettings, databaseName, options); configuration.UseStorage(storage); return storage; }
/// <summary> /// /// </summary> /// <param name="configuration"></param> /// <returns></returns> /// <exception cref="ArgumentNullException"></exception> public static IGlobalConfiguration <LiteDbStorage> UseLiteDbStorage( [NotNull] this IGlobalConfiguration configuration) { if (configuration == null) { throw new ArgumentNullException(nameof(configuration)); } var storage = new LiteDbStorage("Hangfire.db", new LiteDbStorageOptions()); return(configuration.UseStorage(storage)); }
/// <summary> /// Configure Hangfire to use MongoDB storage /// </summary> /// <param name="configuration">Configuration</param> /// <param name="mongoClient">Client for Mongo</param> /// <param name="databaseName">Name of database at Mongo server</param> /// <param name="storageOptions">Storage options</param> /// <returns></returns> public static MongoStorage UseMongoStorage(this IGlobalConfiguration configuration, MongoClient mongoClient, string databaseName, MongoStorageOptions storageOptions) { var storage = new MongoStorage(mongoClient, databaseName, storageOptions); configuration.UseStorage(storage); return(storage); }
public static IGlobalConfiguration <ObjectRepositoryStorage> UseHangfireStorage( [NotNull] this IGlobalConfiguration configuration, ObjectRepositoryBase objectRepository) { if (configuration == null) { throw new ArgumentNullException(nameof(configuration)); } var storage = new ObjectRepositoryStorage(objectRepository); return(configuration.UseStorage(storage)); }
public static IGlobalConfiguration <EFCoreStorage> UseEFCoreStorage( [NotNull] this IGlobalConfiguration configuration, [NotNull] Action <DbContextOptionsBuilder> optionsAction, [NotNull] EFCoreStorageOptions options) { if (configuration is null) { throw new ArgumentNullException(nameof(configuration)); } return(configuration.UseStorage(new EFCoreStorage(optionsAction, options))); }
/// <summary> /// Enables to attach Azure Cosmos DB to Hangfire /// </summary> /// <param name="configuration">The IGlobalConfiguration object</param> /// <param name="cosmosClient">An instance of CosmosClient</param> /// <param name="databaseName">The name of the database to connect with</param> /// <param name="containerName">The name of the container on the database</param> /// <param name="storageOptions">The CosmosDbStorage object to override any of the options</param> /// <param name="cancellationToken"></param> /// <returns></returns> public static async Task <IGlobalConfiguration <CosmosDbStorage> > UseAzureCosmosDbStorageAsync(this IGlobalConfiguration configuration, CosmosClient cosmosClient, string databaseName, string containerName, CosmosDbStorageOptions?storageOptions = null, CancellationToken cancellationToken = default) { if (configuration == null) { throw new ArgumentNullException(nameof(configuration)); } CosmosDbStorage storage = await CosmosDbStorage.CreateAsync(cosmosClient, databaseName, containerName, storageOptions, cancellationToken); return(configuration.UseStorage(storage)); }
public static IGlobalConfiguration <RavenStorage> UseRavenStorage(this IGlobalConfiguration configuration, string connectionString) { configuration.ThrowIfNull("configuration"); connectionString.ThrowIfNull("connectionString"); var config = new RepositoryConfig() { ConnectionStringName = connectionString }; var storage = new RavenStorage(config); return(configuration.UseStorage(storage)); }
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>("HangfirePostgreConnectionString"); if (!string.IsNullOrEmpty(envSqlConnectStr)) { sqlConnectStr = envSqlConnectStr; } PostgreSqlStorage storage = new PostgreSqlStorage(sqlConnectStr); globalConfiguration .UseStorage(storage) .UseConsole(new ConsoleOptions { BackgroundColor = "#000079" }) .UseTagsWithPostgreSql(new TagsOptions() { TagsListStyle = TagsListStyle.Dropdown }) .UseHangfireHttpJob(httpJobOptions) .UseHeartbeatPage(); }
public static IGlobalConfiguration <RedisStorage> UseRedisStorage(this IGlobalConfiguration configuration, string OptionString, int db, string Prefix) { if (configuration == null) { throw new ArgumentNullException("configuration"); } if (OptionString == null) { throw new ArgumentNullException("OptionString"); } var storage = new RedisStorage(OptionString, db, Prefix); return(configuration.UseStorage(storage)); }
public static IGlobalConfiguration <RedisStorage> UseRedisStorage(this IGlobalConfiguration configuration, ConfigurationOptions Options) { if (configuration == null) { throw new ArgumentNullException("configuration"); } if (Options == null) { throw new ArgumentNullException("Options"); } var storage = new RedisStorage(Options); return(configuration.UseStorage(storage)); }
/// <summary> /// 启用基于CSRedisCore实现的Redis存储 /// </summary> /// <param name="configuration">Hangfire全局配置</param> /// <param name="nameOrConnectionString">连接字符串</param> /// <param name="options">Redis存储选项配置</param> public static IGlobalConfiguration <RedisStorage> UseRedisStorage([NotNull] this IGlobalConfiguration configuration, [NotNull] string nameOrConnectionString, RedisStorageOptions options = null) { if (configuration == null) { throw new ArgumentNullException(nameof(configuration)); } if (nameOrConnectionString == null) { throw new ArgumentNullException(nameof(nameOrConnectionString)); } var storage = new RedisStorage(nameOrConnectionString, options); return(configuration.UseStorage(storage)); }