ABP框架系列之四十五:(Quartz-Integration-Quartz-集成)
Introduction
Quartz is a is a full-featured, open source job scheduling system that can be used from smallest apps to large scale enterprise systems. Abp.Quartz package simply integrates Quartz to ASP.NET Boilerplate.
Quartz是一个功能齐全的开源作业调度系统,可以从最小的应用程序到大型企业系统使用。Abp.Quartz包简单地集成ASP.NET样板。
ASP.NET Boilerplate has a built-in persistent background job queue and background worker system. Quartz can be a good alternative if you have advanced scheduling requirements for your background workers. Also,Hangfire can be a good alternative for persistent background job queue.
ASP.NET的模板有一个内置的持久后台作业队列和背景工人系统。如果你对你的背景工作者有高级的进度要求,Quartz是一个不错的选择。另外,迟发性可以持续背景任务队列的一个很好的选择。
Installation
Install Abp.Quartznuget package to your project and add a DependsOn attribute to your module for AbpQuartzModule:
[DependsOn(typeof (AbpQuartzModule))]
public class YourModule : AbpModule
{
//...
}
Creating Jobs
To create a new job, you can either implement Quartz's IJob interface, or derive from JobBase class (defined in Abp.Quartz package) that has some helper properties/methods (for logging and localization for example). A simple job class is shown below:
创建一个新的工作,你可以实现 Quartz的ijob接口,或者从jobbase类(ABP。石英包中定义的),有一些辅助属性/方法(记录和定位为例)。下面显示一个简单的作业类:
public class MyLogJob : JobBase, ITransientDependency
{
public override void Execute(IJobExecutionContext context)
{
Logger.Info("Executed MyLogJob :)");
}
}
We simply implemented the Execute method to write a log. You can see Quartz's documentation for more.
Schedule Jobs(安排工作)
IQuartzScheduleJobManager is used to schedule jobs. You can inject it to your class (or you can Resolve and use it in your module's PostInitialize method) to schedule jobs. An example Controller that schedules a job:
iquartzschedulejobmanager来安排工作。你可以将它注入到你的类(或你可以解决和使用你的模块的postinitialize法)安排工作。调度工作的示例控制器:
public class HomeController : AbpController
{
private readonly IQuartzScheduleJobManager _jobManager; public HomeController(IQuartzScheduleJobManager jobManager)
{
_jobManager = jobManager;
} public async Task<ActionResult> ScheduleJob()
{
await _jobManager.ScheduleAsync<MyLogJob>(
job =>
{
job.WithIdentity("MyLogJobIdentity", "MyGroup")
.WithDescription("A job to simply write logs.");
},
trigger =>
{
trigger.StartNow()
.WithSimpleSchedule(schedule =>
{
schedule.RepeatForever()
.WithIntervalInSeconds(5)
.Build();
});
}); return Content("OK, scheduled!");
}
}
More
Please see Quartz's documentation for more information about Quartz.
ABP框架系列之四十五:(Quartz-Integration-Quartz-集成)的更多相关文章
- ABP框架系列之四十九:(Startup-Configuration-启动配置)
ASP.NET Boilerplate provides an infrastructure and a model to configure it and modules on startup. A ...
- ABP框架系列之十五:(Caching-缓存)
Introduction ASP.NET Boilerplate provides an abstraction for caching. It internally uses this cache ...
- ABP框架系列之四十二:(Object-To-Object-Mapping-对象映射)
Introduction It's a common to map a similar object to another object. It's also tedious and repeatin ...
- ABP框架系列之四十:(Notification-System-通知系统)
Introduction Notifications are used to inform users on specific events in the system. ASP.NET Boiler ...
- ABP框架系列之四十四:(OWIN)
If you are using both of ASP.NET MVC and ASP.NET Web API in your application, you need to add Abp.Ow ...
- ABP框架系列之四十六:(Setting-Management-设置管理)
Introduction Every application need to store some settings and use these settings in somewhere in th ...
- ABP框架系列之四十八:(Specifications-规范)
Introduction Specification pattern is a particular software design pattern, whereby business rules c ...
- ABP框架系列之三十五:(MVC-Controllers-MVC控制器)
Introduction ASP.NET Boilerplate is integrated to ASP.NET MVC Controllers via Abp.Web.Mvc nuget pack ...
- ABP框架系列之五十四:(XSRF-CSRF-Protection-跨站请求伪造保护)
Introduction "Cross-Site Request Forgery (CSRF) is a type of attack that occurs when a maliciou ...
随机推荐
- c# HashTable (哈希表)
HashTable 哈希表 也是System.Collections集合下的数据结构类 它储存的也是Object类型的对象 但是它在内存中是散列排布的 因为这个特性,非常适合存储大量的数据 在Hash ...
- 《女神异闻录 5》的 UI 设计
转自:https://www.zhihu.com/question/50995871?sort=created <女神异闻录5>是近两年最为火热的JRPG游戏之一,它的出色不仅在于剧情暗讽 ...
- 查看Linux内置命令和外部命令
1. [hl@localhost ~]$ which cd /bin/cd [hl@localhost ~]$ type cd cd is a shell builtin
- Numpy学习笔记(二)
(1)NumPy - 切片和索引 l ndarray对象中的元素遵循基于零的索引. 有三种可用的索引方法类型: 字段访问,基本切片和高级索引. l 基本切片 Python 中基本切片概念到 n 维 ...
- C# 自定义异常的方法源码演示及说明
内容之余,把做工程过程中较好的内容段备份一下,下边内容是关于C# 自定义异常的方法演示及说明的内容,希望能对各位朋友有一些好处. using System;using System.Collectio ...
- 堆排序(Heapsort)
class Program { static void Main(string[] args) { , , , , , ,}; int size = arr.Length; Heapsort(arr, ...
- Python:笔记1_字符串处理【转载】
[转载自:https://www.cnblogs.com/houht/p/3308634.html] 1. 判断字符串str是否为空Approach 1:如果字符串长度为0,说明字符串为空,code如 ...
- 编写Servlet 实例 -Shopping网站时,遇到的几个问题
问题一.在Web 上运行时,用JDBC链接MySQL总是出错,一直出现驱动加载失败 ------提示java.lang.ClassNotFoundException.解决方案:将数据库驱动jar文件导 ...
- css学习2
1.垂直居中 -父元素高度确定的单行文本: 设置父元素的 height 和 line-height 高度一致来实现的.(height: 该元素的高度:line-height: 行高(行间距),指在文 ...
- mysql实用函数
1. group_concat(); 可以将选择的字段列数据,分组以逗号分隔成一串.实用方便.select id,group_concat(distinct name) from ttt group ...