Hangfire.HttpJob for Hangfire
add delay background job by [http post] or on dashbord
add recurring job by [http post] or on dashbord
search job by jobname on dashbord
stop or start job on dashbord
cron generator on dashbord
use Hangfire.HttpJob.Agent extention to quick develop job program
6.1 Make your webjob very convenient to support scheduling execution
6.2 Visualizing the execution process of webjob by logs and progress on hangfire dashbord
6.3 Variety of webjob types with different life cycles
6.3.1 Singleton
6.3.2 Transient
6.3.3 Hang up until stop command
00.QickStart DockerQuickStart
01.how to create backgroud httpjob
02.how to create recurringHttpJob
03.how to use HttpJob.Agent
04.how to use in sqlserver
05.how to config mail service to report job result
https://github.com/yuzd/Hangfire.HttpJob/wiki
This library is available as a NuGet Package:
Install-Package Hangfire.HttpJob
Install-Package Hangfire.HttpJob.Agent
Install-Package Hangfire.HttpJob.Client
//StartUp.cs
public virtual void ConfigureServices(IServiceCollection services)
{
services.AddHangfire(Configuration);//Configuration是下面的方法
}
private void Configuration(IGlobalConfiguration globalConfiguration)
{
globalConfiguration.UseStorage(
new MySqlStorage(
"Server=localhost;Port=3306;Database=hangfire;Uid=root;Pwd=123456;charset=utf8;SslMode=none;Allow User Variables=True",
new MySqlStorageOptions
{
TransactionIsolationLevel = IsolationLevel.ReadCommitted,
QueuePollInterval = TimeSpan.FromSeconds(15),
JobExpirationCheckInterval = TimeSpan.FromHours(1),
CountersAggregateInterval = TimeSpan.FromMinutes(5),
PrepareSchemaIfNecessary = false,
DashboardJobListLimit = 50000,
TransactionTimeout = TimeSpan.FromMinutes(1),
}))
.UseConsole()
.UseHangfireHttpJob();
}
public void Configure(IApplicationBuilder app)
{
app.UseHangfireServer();
app.UseHangfireDashboard("/hangfire",new DashboardOptions
{
Authorization = new[] { new BasicAuthAuthorizationFilter(new BasicAuthAuthorizationFilterOptions
{
RequireSsl = false,
SslRedirect = false,
LoginCaseSensitive = true,
Users = new []
{
new BasicAuthAuthorizationUser
{
Login = "admin",
PasswordClear = "test"
}
}
}) }
});
}
Install-Package Hangfire.HttpJob.Client
var serverUrl = "http://localhost:5000/job";
var result = HangfireJobClient.AddBackgroundJob(serverUrl, new BackgroundJob
{
JobName = "测试api",
Method = "Get",
Url = "http://localhost:5000/testaaa",
Mail = new List<string> {"1877682825@qq.com"},
SendSucMail = true,
DelayFromMinutes = 1
}, new HangfireServerPostOption
{
BasicUserName = "admin",
BasicPassword = "test"
});
var result = HangfireJobClient.AddRecurringJob(serverUrl, new RecurringJob()
{
JobName = "测试5点40执行",
Method = "Post",
Data = new {name = "aaa",age = 10},
Url = "http://localhost:5000/testpost",
Mail = new List<string> { "1877682825@qq.com" },
SendSucMail = true,
Cron = "40 17 * * *"
}, new HangfireServerPostOption
{
BasicUserName = "admin",
BasicPassword = "test"
});
1.add backgroundjob
url:http://{hangfireserver}/hangfire/httpjob?op=backgroundjob
method:post
data:
{
"Method": "POST",
"ContentType": "application/json",
"Url": "http://XXXXXXX",
"DelayFromMinutes": 1,
"Data": "{\"userName\":\"test\"}",
"Timeout": 5000,
"BasicUserName": "",// 如果你希望hangfire执行http的时候带basic认证的话 就设置这2个参数
"BasicPassword": "",
"JobName": "test_backgroundjob"
}
2.add recurringjob
url:http://{hangfireserver}/hangfire/httpjob?op=recurringjob
method:post
data:
{
"Method": "POST",
"ContentType": "application/json",
"Url": "http://XXXXXXX",
"Data": "{\"userName\":\"test\"}",
"Timeout": 5000,
"Corn": "0 12 * */2",
"BasicUserName": "",// 如果你希望hangfire执行http的时候带basic认证的话 就设置这2个参数
"BasicPassword": "",
"JobName": "test_recurringjob"
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。