FluentScheduler:开源轻量级定时任务调度架构
安装:FluentScheduler
Install-Package FluentScheduler
一、控制台中使用
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using FluentScheduler; namespace ConsoleApp
{
class Program
{
static void Main(string[] args)
{
//两个参数分别:Job、调度时间
JobManager.AddJob(() =>
{
//任务逻辑
Console.WriteLine("Timer task,current time:{0}", DateTime.Now);
}, t =>
{
//时间 //从程序启动开始执行,然后每秒钟执行一次
t.ToRunNow().AndEvery().Seconds();
////带有任务名称的任务定时器
//t.WithName("TimerTask").ToRunOnceAt(DateTime.Now.AddSeconds(5));
}); Console.ReadKey();
}
}
}
program.cs
二、Web中使用
1、任务逻辑
using System;
using System.Diagnostics;
using System.Threading;
using FluentScheduler; namespace WebApp.Models
{
public class MyJob:Registry
{
public MyJob()
{
// 每2秒一次循环
Schedule<MyJob1>().ToRunNow().AndEvery().Seconds(); // 5秒后,只一次
Schedule<MyOtherJob>().ToRunOnceIn().Seconds(); //每天晚上21:15分执行
Schedule(() => Console.WriteLine("Timed Task - Will run every day at 9:15pm: " + DateTime.Now)).ToRunEvery().Days().At(, ); // 每个月的执行
Schedule(() =>
{
Console.WriteLine("Complex Action Task Starts: " + DateTime.Now);
Thread.Sleep();
Console.WriteLine("Complex Action Task Ends: " + DateTime.Now);
}).ToRunNow().AndEvery().Months().OnTheFirst(DayOfWeek.Monday).At(, ); //先执行第一个Job、再执行第二个Job;完成后等5秒继续循环
Schedule<MyFirstJob>().AndThen<MySecoundJob>().ToRunNow().AndEvery().Seconds();
}
} public class MyJob1 : IJob
{ void IJob.Execute()
{
Trace.WriteLine("循环每2秒执行一次;现在时间是:" + DateTime.Now);
}
} public class MyOtherJob : IJob
{ void IJob.Execute()
{
Trace.WriteLine("5秒后只执行一次 ,现在时间是:" + DateTime.Now);
}
} public class MyFirstJob : IJob
{ void IJob.Execute()
{
Trace.WriteLine("执行第一个 Job ,现在时间是:" + DateTime.Now);
}
}
public class MySecoundJob : IJob
{ void IJob.Execute()
{
Trace.WriteLine("执行第二个 Job ,现在时间是:" + DateTime.Now);
}
} }
MyJob
2、初始化
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Web.Optimization;
using System.Web.Routing;
using FluentScheduler;
using WebApp.Models; namespace WebApp
{
public class MvcApplication : System.Web.HttpApplication
{
protected void Application_Start()
{
AreaRegistration.RegisterAllAreas();
FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
RouteConfig.RegisterRoutes(RouteTable.Routes);
BundleConfig.RegisterBundles(BundleTable.Bundles); JobManager.Initialize(new MyJob());
}
}
}
Global.asax.cs
源码:
https://github.com/fluentscheduler/FluentScheduler
FluentScheduler:开源轻量级定时任务调度架构的更多相关文章
- 开源一个定时任务调度器 webscheduler
在企业应用中定时任务调度的需求是必不可少的,比如定时同步数据,定时结转数据,定时检测异常等等.公司之前是在使用一款采用.net 开发的windows服务形式的定时程序,基本能满足需求,在一段时间的时候 ...
- python中的轻量级定时任务调度库:schedule
提到定时任务调度的时候,相信很多人会想到芹菜celery,要么就写个脚本塞到crontab中.不过,一个小的定时脚本,要用celery的话太“重”了.所以,我找到了一个轻量级的定时任务调度的库:sch ...
- 11: python中的轻量级定时任务调度库:schedule
1.1 schedule 基本使用 1.schedule 介绍 1. 提到定时任务调度的时候,相信很多人会想到芹菜celery,要么就写个脚本塞到crontab中. 2. 不过,一个小的定时脚本,要用 ...
- 记录对定时任务调度器的小小改进 - API调度计划
之前记录过一篇 [开源一个定时任务调度器 webscheduler],这是一个看似简单的小工具,昨天部署到服务器上开始试用下,听听反馈. 项目经理看过后,立马反馈说这个使用 Cron表达式 的计划太难 ...
- C#/.NET/.NET Core定时任务调度的方法或者组件有哪些--Timer,FluentScheduler,TaskScheduler,Gofer.NET,Coravel,Quartz.NET还是Hangfire?
原文由Rector首发于 码友网 之 <C#/.NET/.NET Core应用程序编程中实现定时任务调度的方法或者组件有哪些,Timer,FluentScheduler,TaskSchedule ...
- C#/.NET/.NET Core定时任务调度的方法或者组件有哪些--Timer,FluentScheduler还是...
原文:C#/.NET/.NET Core定时任务调度的方法或者组件有哪些--Timer,FluentScheduler还是... 原文由Rector首发于 码友网 之 <C#/.NET/.NET ...
- 分布式定时任务调度系统技术解决方案(xxl-job、Elastic-job、Saturn)
1.业务场景 保险人管系统每月工资结算,平安有150万代理人,如何快速的进行工资结算(数据运算型) 保险短信开门红/电商双十一 1000w+短信发送(短时汇聚型) 工作中业务场景非常多,所涉及到的场景 ...
- #研发中间件介绍#定时任务调度与管理JobCenter
郑昀 最后更新于2014/11/11 关键词:定时任务.调度.监控报警.Job.crontab.Java 本文档适用人员:研发员工 没有JobCenter时我们要面对的: 电商业务链条很长,业 ...
- 免费开源的DotNet任务调度组件Quartz.NET(.NET组件介绍之五)
很多的软件项目中都会使用到定时任务.定时轮询数据库同步,定时邮件通知等功能..NET Framework具有“内置”定时器功能,通过System.Timers.Timer类.在使用Timer类需要面对 ...
随机推荐
- 壁虎书4 Training Models
Linear Regression The Normal Equation Computational Complexity 线性回归模型与MSE. the normal equation: a cl ...
- html 常用标签 a form input 标签 等等等
前端HTML HTML介绍 Web服务本质 import socket sk = socket.socket() sk.bind(("127.0.0.1", 8080)) sk ...
- [No0000173]97 条 Linux 常用命令总结
1.ls [选项] [目录名 | 列出相关目录下的所有目录和文件 -a 列出包括.a开头的隐藏文件的所有文件-A 通-a,但不列出"."和".."-l 列 ...
- Java NIO 读取文件、写入文件、读取写入混合
前言 Java NIO(new/inputstream outputstream)使用通道.缓冲来操作流,所以要深刻理解这些概念,尤其是,缓冲中的数据结构(当前位置(position).限制(limi ...
- ATM JAVA实现 部分代码
package score;//信1705-2 20173600 王重阳 import java.util.Scanner; public class Main { public static voi ...
- Uniform Resource Name Server
HTTP The Definitive Guide 按址标识 identify by address 按名标识 identify by name Domain Name Server Uniform ...
- get post header获取数据方方法
/** * get方式获取数据 * @param $url * @param $data * @return bool|string */public function methodGet($url, ...
- 新装的Delphi XE10 空白的安卓程序编译报错 F1027 Unit not found: 'System.pas'
没有安装 安卓的lib 和 PlatformSDKs 把相关压缩包解压缩后,将对应文件夹android放在lib下面 , PlatformSDKs放在D:\Program Files (x86)\Em ...
- LeetCode 690 Employee Importance 解题报告
题目要求 You are given a data structure of employee information, which includes the employee's unique id ...
- LeetCode 812 Largest Triangle Area 解题报告
题目要求 You have a list of points in the plane. Return the area of the largest triangle that can be for ...