背景
大部分业务都是基于定时的任务,特别适合使用quartz这类框架解决定时问题。具体quartz的使用,看官方文档就可以了。下面谈谈对quartz插件化的封装。我们使用quartz.plugin。然后在quartz_jobs.
解决思路
在实际使用中,开发就变得相对简单了,不需要关注job任务是如何被调度的。只需要在程序中定义一个类实现job接口,填充业务代码,然后在文件里面填写该job属性:
[DisallowConcurrentExecution] public class AnalysisJob : IJob { public void Execute(IJobExecutionContext context) { xxxxxxxxxx } } <job> <name>名称</name> <group>分组</group> <description>描述</description> <job-type>类库</job-type> <durable>true</durable> <recover>false</recover> </job>这样的封装就赋予框架新的技能,大大提高了开发人员的开发效率。

主要代码
using System;using System.Collections.Generic;using System.Linq;using Topshelf;namespace HSCP.Task{ class Program { static void Main(string[] args) { HostFactory.Run(x => { x.Service<MainService>((s) => { s.ConstructUsing(settings => new MainService()); s.WhenStarted(tr => tr.Start()); s.WhenStopped(tr => tr.Stop()); }); x.RunAsLocalSystem(); x.SetDescription(""); x.SetDisplayName("xxxx任务管理器"); x.SetServiceName("HSCP.Task"); }); } }}using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Threading.Tasks;using Quartz;using Quartz.Impl;namespace HSCP.Task{ class MainService { static IScheduler sched; public void Start() { try { ISchedulerFactory factory = new StdSchedulerFactory(); sched = factory.GetScheduler(); sched.Start(); Console.WriteLine($"共 {sched.GetJobGroupNames().Count} 任务"); foreach (string gn in sched.GetJobGroupNames()) Console.WriteLine(gn); } catch (Exception exc) { Console.WriteLine(exc.ToString()); } // NLogger.Info(string.Format("启动成功 {0}", DateTime.Now)); } public void Stop() { sched.Shutdown(true); } }}开源地址
https://github.com/quartznet/quartznet
原文转载:http://www.shaoqun.com/a/508487.html
杨颜:https://www.ikjzd.com/w/1820
跨境通电子商务平台:https://www.ikjzd.com/w/1329.html
背景大部分业务都是基于定时的任务,特别适合使用quartz这类框架解决定时问题。具体quartz的使用,看官方文档就可以了。下面谈谈对quartz插件化的封装。我们使用quartz.plugin。然后在quartz_jobs.解决思路在实际使用中,开发就变得相对简单了,不需要关注job任务是如何被调度的。只需要在程序中定义一个类实现job接口,填充业务代码,然后在文件里面填写该job属性:[Dis
易佰:易佰
bap:bap
公司企业植树节活动方案:公司企业植树节活动方案
丹麦美食旅游攻略:丹麦美食旅游攻略
天堂中的美景非诚勿扰2拍摄地揭秘 :天堂中的美景非诚勿扰2拍摄地揭秘
没有评论:
发表评论
注意:只有此博客的成员才能发布评论。