All Projects → icsharp → Hangfire.recurringjobextensions

icsharp / Hangfire.recurringjobextensions

Licence: mit
Extensions for Hangfire to build RecurringJob automatically

Labels

Projects that are alternatives of or similar to Hangfire.recurringjobextensions

Magazine Website Akka
The experiment on the akkadotnet
Stars: ✭ 21 (-84.56%)
Mutual labels:  quartz
Seppb
普兰能效平台开源版(后端)
Stars: ✭ 104 (-23.53%)
Mutual labels:  quartz
Ibase4j
Spring,SpringBoot 2.0,SpringMVC,Mybatis,mybatis-plus,motan/dubbo分布式,Redis缓存,Shiro权限管理,Spring-Session单点登录,Quartz分布式集群调度,Restful服务,QQ/微信登录,App token登录,微信/支付宝支付;日期转换、数据类型转换、序列化、汉字转拼音、身份证号码验证、数字转人民币、发送短信、发送邮件、加密解密、图片处理、excel导入导出、FTP/SFTP/fastDFS上传下载、二维码、XML读写、高精度计算、系统配置工具类等等。
Stars: ✭ 1,548 (+1038.24%)
Mutual labels:  quartz
Cronner
Cronner 是一个分布式定时任务框架,支持作业依赖、分片、失效转移、集中配置和监控。
Stars: ✭ 51 (-62.5%)
Mutual labels:  quartz
Attemper
Distributed,multi-tenancy,job-flow scheduling application(分布式多租户的支持流程编排的任务调度平台) QQ群:1029617143
Stars: ✭ 86 (-36.76%)
Mutual labels:  quartz
Ruoyi Vue Fast
(RuoYi)官方仓库 基于SpringBoot,Spring Security,JWT,Vue & Element 的前后端分离权限管理系统
Stars: ✭ 107 (-21.32%)
Mutual labels:  quartz
Shardingsphere Elasticjob
Distributed scheduled job framework
Stars: ✭ 7,369 (+5318.38%)
Mutual labels:  quartz
Xc Spring Cloud Alibaba
spring cloud alibaba(2.2.1最新版)+nacos+dubbo+gateWay+sentinel+rocketmq+(pgsql/mysql8.0的json支持)+ignite集成可用于docker分布式框架+分布式自动化任务+mybatis多数据源+seate+ shardingSphere分布式分库事务解决方案
Stars: ✭ 131 (-3.68%)
Mutual labels:  quartz
Springboot Quartz
quartz + springboot + RabbitMQ + H2(in-memory database) + dynamic task management web console.
Stars: ✭ 103 (-24.26%)
Mutual labels:  quartz
Zeusspring
基于Spring Boot 2.0的前后端分离的快速开发平台,此仓库是后台部分; 前台:Vue+Element 后台:Spring Boot 2.0/Spring Security/JWT/Spring Data JPA+Mybatis-Plus/Redis/分布式限流/同步锁/验证码/动态权限管理 数据权限 工作流 代码生成 日志记录 第三方社交账号、短信登录
Stars: ✭ 117 (-13.97%)
Mutual labels:  quartz
Commonx
基础框架
Stars: ✭ 57 (-58.09%)
Mutual labels:  quartz
Quartz Demo
Demo project for Spring Boot 2 and Quartz scheduler integration
Stars: ✭ 63 (-53.68%)
Mutual labels:  quartz
Spring Boot Quartz Scheduler Email Scheduling
Spring Boot Quartz Scheduler Example that schedules Emails to be sent at a later time.
Stars: ✭ 109 (-19.85%)
Mutual labels:  quartz
Spring Batch Admin Backend
Spring Batch Admin 是一个后端采用spring boot 2, spring security , oauth2, Spring data jpa 作为基础框架,集成了quartz 提供调度能力,集成了Spring batch 提供批处理能力的管理系统。系统旨在提供更底层数据展示以及常见批处理的配置以及运行能力。
Stars: ✭ 41 (-69.85%)
Mutual labels:  quartz
Go Quartz
Simple, zero-dependency scheduling library for Go
Stars: ✭ 118 (-13.24%)
Mutual labels:  quartz
Ruoyi
(RuoYi)官方仓库 基于SpringBoot的权限管理系统 易读易懂、界面简洁美观。 核心技术采用Spring、MyBatis、Shiro没有任何其它重度依赖。直接运行即可用
Stars: ✭ 905 (+565.44%)
Mutual labels:  quartz
Spring Quartz Demo
spring整合quartz动态定时任务demo
Stars: ✭ 105 (-22.79%)
Mutual labels:  quartz
Ruoyi Oracle
(RuoYi)官方仓库 基于SpringBoot的权限管理系统 易读易懂、界面简洁美观。 核心技术采用Spring、MyBatis、Shiro没有任何其它重度依赖。直接运行即可用
Stars: ✭ 134 (-1.47%)
Mutual labels:  quartz
Sk Admin
基于 Spring Boot、 Spring Data JPA、 Spring Security、Vue 的前后端分离的管理系统。项目采用模块开发方式, 主要模块:权限管理 (RBAC(Role-Based Access Control,基于角色的访问控制),支持数据字典、数据权限管理、前端菜单支持动态路由)、日志管理、代码生成器、系统监控、云存储管理、系统工具等等
Stars: ✭ 130 (-4.41%)
Mutual labels:  quartz
Milkomeda
Spring extend componets which build from experience of bussiness, let developers to develop with Spring Boot as fast as possible.(基于Spring生态打造的一系列来自业务上的快速开发模块集合。)
Stars: ✭ 117 (-13.97%)
Mutual labels:  quartz

Hangfire.RecurringJobExtensions

Official Site NuGet Build status License MIT

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.

public class RecurringJobService
{
    [RecurringJob("*/1 * * * *")]
    [Queue("jobs")]
    public void TestJob1(PerformContext context)
    {
        context.WriteLine($"{DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss")} TestJob1 Running ...");
    }
    [RecurringJob("*/2 * * * *", RecurringJobId = "TestJob2")]
    [Queue("jobs")]
    public void TestJob2(PerformContext context)
    {
        context.WriteLine($"{DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss")} TestJob2 Running ...");
    }
    [RecurringJob("*/2 * * * *", "China Standard Time", "jobs")]
    public void TestJob3(PerformContext context)
    {
        context.WriteLine($"{DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss")} TestJob3 Running ...");
    }
    [RecurringJob("*/5 * * * *", "jobs")]
    public void InstanceTestJob(PerformContext context)
    {
        context.WriteLine($"{DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss")} InstanceTestJob Running ...");
    }

    [RecurringJob("*/6 * * * *", "UTC", "jobs")]
    public static void StaticTestJob(PerformContext context)
    {
        context.WriteLine($"{DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss")} StaticTestJob Running ...");
    }
}

Json Configuration

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

[AutomaticRetry(Attempts = 0)]
[DisableConcurrentExecution(90)]
public class LongRunningJob : IRecurringJob
{
    public void Execute(PerformContext context)
    {
        context.WriteLine($"{DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss")} LongRunningJob Running ...");

        var runningTimes = context.GetJobData<int>("RunningTimes");

        context.WriteLine($"get job data parameter-> RunningTimes: {runningTimes}");

        var progressBar = context.WriteProgressBar();

        foreach (var i in Enumerable.Range(1, runningTimes).ToList().WithProgress(progressBar))
        {
            Thread.Sleep(1000);
        }
    }
}

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

[{
    "job-name": "My Job1",
    "job-type": "Hangfire.Samples.MyJob1, Hangfire.Samples",
    "cron-expression": "*/1 * * * *",
    "timezone": "China Standard Time",
    "queue": "jobs"
},
{
    "job-name": "My Job2",
    "job-type": "Hangfire.Samples.MyJob2, Hangfire.Samples",
    "cron-expression": "*/5 * * * *",
    "job-data": {
        "IntVal": 1,
        "StringVal": "abcdef",
        "BooleanVal": true,
        "SimpleObject": {
            "Name": "Foo",
            "Age": 100
        }
    }
},
{
    "job-name": "Long Running Job",
    "job-type": "Hangfire.Samples.LongRunningJob, Hangfire.Samples",
    "cron-expression": "*/2 * * * *",
    "job-data": {
        "RunningTimes": 300
    }
}]

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<string,object>.
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.

var intVal = context.GetJobData<int>("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.

//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.

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.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].