hangfire.mysql.core_Hangfire的Mysql存储组件

Hangfire.MySql.Core是Hangfire的Mysql存储组件,修复了部分bug并支持.NET Standard 2.0。它是一个可靠的后台作业运行器,支持多服务器、CPU和I/O密集型任务。现在可以设置表前缀。安装通过NuGet包管理器安装Hangfire.MySql.Core,初始化时可以指定连接字符串和选项,例如设置交易隔离级别、队列轮询间隔等。
摘要由CSDN通过智能技术生成

Hangfire.MySql.Core Implementation

Hangfire.MySql.Core is based on Hangfire.MySqlStorage(https://github.com/arnoldasgudas/Hangfire.MySqlStorage)

I fix some bug and support .net standard 2.0

68747470733a2f2f696d672e736869656c64732e696f2f6e756765742f762f48616e67666972652e4d7953716c2e436f72652e737667

MySql storage implementation of Hangfire - fire-and-forget, delayed and recurring tasks runner for .NET. Scalable and reliable background job runner. Supports multiple servers, CPU and I/O intensive, long-running and short-running jobs.

Now, support table prefix

services.AddHangfire(x => x.UseStorage(new MySqlStorage(Configuration.GetConnectionString("Hangfire"),new MySqlStorageOptions(){TablePrefix = "Custom"})));

Installation

Install MySQL

Run the following command in the NuGet Package Manager console to install Hangfire.MySql.Core:

Install-Package Hangfire.MySql.Core

Usage

Use one the following ways to initialize MySqlStorage:

Create new instance of MySqlStorage with connection string constructor parameter and pass it to Configuration with UseStorage method:

GlobalConfiguration.Configuration.UseStorage(

new MySqlStorage(connectionString));

There must be Allow User Variables set to true in the connection string. For example: server=127.0.0.1;uid=root;pwd=root;database={0};Allow User Variables=True

Alternatively one or more options can be passed as a parameter to MySqlStorage:

GlobalConfiguration.Configuration.UseStorage(

new MySqlStorage(

connectionString,

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"

}));

Description of optional parameters:

TransactionIsolationLevel - transaction isolation level. Default is read committed.

QueuePollInterval - job queue polling interval. Default is 15 seconds.

JobExpirationCheckInterval - job expiration check interval (manages expired records). Default is 1 hour.

CountersAggregateInterval - interval to aggregate counter. Default is 5 minutes.

PrepareSchemaIfNecessary - if set to true, it creates database tables. Default is true.

DashboardJobListLimit - dashboard job list limit. Default is 50000.

TransactionTimeout - transaction timeout. Default is 1 minute.

How to limit number of open connections

Number of opened connections depends on Hangfire worker count. You can limit worker count by setting WorkerCount property value in BackgroundJobServerOptions:

app.UseHangfireServer(

new BackgroundJobServerOptions

{

WorkerCount = 1

});

Dashboard

Hangfire provides a dashboard 687474703a2f2f68616e67666972652e696f2f696d672f75692f64617368626f6172642d736d2e706e67 More info: Hangfire Overview

Build

Please use Visual Studio or any other tool of your choice to build the solution

Test

In order to run unit tests and integrational tests set the following variables in you system environment variables (restart of Visual Studio is required):

Hangfire_SqlServer_ConnectionStringTemplate (default: server=127.0.0.1;uid=root;pwd=root;database={0};Allow User Variables=True)

Hangfire_SqlServer_DatabaseName (default: Hangfire.MySql.Tests)

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值