百科.dev
全部条目在线工具AI 编程趋势榜开源项目技术资讯提交条目
登录
< 返回工具列表
H

Hangfire.RecurringJobExtensions

> 后端框架
开源

Hangfire 扩展,可自动构建 RecurringJob

185 stars0 点赞1 次浏览
访问官网GitHub

工具介绍

Hangfire 扩展,可自动构建 RecurringJob

Hangfire.RecurringJobExtensions

This repo is the extension for Hangfire to build RecurringJob automatically. When app start, RecurringJob will be added/updated automatically. There is two ways to build RecurringJob.

  • RecurringJobAttribute attribute
  • Json Configuration

Using RecurringJobAttribute

We can use the attribute RecurringJobAttribute to assign the interface/instance/static method.

…

Json Configuration

It is similar to quartz.net, We also define the unified interface IRecurringJob. Recurring jobs must impl the specified interface like this.

…

Now we need to provider the json config file to assign the implemented recurring job, the json configuration samples as below.

…

The json token description to the configuration is here.

JSON Token Description
job-name [required] The job name to RecurringJob.
job-type [required] The job type while impl the interface IRecurringJob.
cron-expression [required] Cron expressions.
timezone [optional] Default value is TimeZoneInfo.Utc.
queue [optional] The specified queue name , default value is default.
job-data [optional] Similar to the quartz.net JobDataMap, it is can be deserialized to the type Dictionary.
enable [optional] Whether the RecurringJob can be added/updated, default value is true, if false RecurringJob will be deleted automatically.

To the json token job-data, we can use extension method to get/set data with specified key from storage which associated with BackgroundJob.Id when recurring job running.

csharp
var intVal = context.GetJobData("IntVal");

context.SetJobData("IntVal", ++intVal);

Building RecurringJob

  • Building with CronJob.

In hangfire client, we can use the helper class CronJob to add or update recurringjob automatically.

csharp
//Builds within specified interface or class.
CronJob.AddOrUpdate(typeof(RecurringJobService1),typeof(RecurringJobService2));

//Builds by using multiple JSON configuration files.
CronJob.AddOrUpdate("recurringjob1.json","recurringjob2.json");
  • Building with IGlobalConfiguration.

Use IGlobalConfiguration extension method UseRecurringJob to build RecurringJob, in .NET Core's Startup.cs.

csharp
public void ConfigureServices(IServiceCollection services)
{
    services.AddHangfire(x =>
    {
        x.UseSqlServerStorage(_config.GetConnectionString("Hangfire"));

        x.UseConsole();

        //using json config file to build RecurringJob automatically.
        x.UseRecurringJob("recurringjob.json");
        //using RecurringJobAttribute to build RecurringJob automatically.
        x.UseRecurringJob(typeof(RecurringJobService));

        x.UseDefaultActivator();
    });
}

For the json configuration file, we can monitor the file change and reload RecurringJob dynamically by passing the parameter reloadOnChange = true.

Issues· 0 开放

查看全部 Issues在 GitHub 打开

暂无开放 Issues,或尚未同步最近议题。

> 标签

C#cron-expressionhangfirejson-configurationquartz

暂无评论,来聊聊你的看法吧

> 工具信息

发布日期2026年8月1日
最后更新2026年9月18日
分类后端框架
定价开源

> 相关工具

N
Node.js
基于 V8 的 JavaScript 运行时
D
Django
Python 高级 Web 框架
S
Spring Boot
Java 生态主流微服务框架