Skip to content

moxixuan/Hangfire.HttpJob

 
 

Repository files navigation

Hangfire.HttpJob for .netcore

Hangfire.HttpJob for Hangfire

Installation

This library is available as a NuGet Package:

Install-Package Hangfire.HttpJob

Usage

	public virtual void ConfigureServices(IServiceCollection services)
	{
		services.AddHangfire(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"
					} 
				}

			}) }
		});
	}

How to add Hangfire.HttpJob by restful api

1.add backgroundjob

url:https://{hangfireserver}/hangfire/httpjob?op=backgroundjob
method:post
data:
{
  "Method": "POST",
  "ContentType": "application/json",
  "Url": "https://XXXXXXX",
  "DelayFromMinutes": 1,
  "Data": "{\"userName\":\"test\"}",
  "Timeout": 5000,
  "BasicUserName": "",// 如果你希望hangfire执行http的时候带basic认证的话 就设置这2个参数
  "BasicPassword": "",
  "JobName": "test_backgroundjob"
}

2.add recurringjob

url:https://{hangfireserver}/hangfire/httpjob?op=recurringjob
method:post
data:
{
  "Method": "POST",
  "ContentType": "application/json",
  "Url": "https://XXXXXXX",
  "Data": "{\"userName\":\"test\"}",
  "Timeout": 5000,
  "Corn": "0 12 * */2",
  "BasicUserName": "",// 如果你希望hangfire执行http的时候带basic认证的话 就设置这2个参数
  "BasicPassword": "",
  "JobName": "test_recurringjob"
}

How to add Hangfire.HttpJob in Dashbord

image image image image

About

httpjob for Hangfire,restful api for Hangfire

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • C# 45.0%
  • CSS 43.3%
  • JavaScript 11.7%