作业引擎quartz.net --- 监听链
针对多个作业:如何描述各个跑批任务之间的顺序,紧前、紧后关系,实现灵活调度。例如:A完成则B开始,B完成C开始。
对quartz.net 进行了查阅,能实现如上业务,如下图:
测试代码:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Quartz;
using Quartz.Impl;
using Quartz.Impl.Matchers;
using Quartz.Listener;
namespace ConsoleApp
{
public class quartznetTest
{
public static void Run()
{
ISchedulerFactory factory = new StdSchedulerFactory();
// Get scheduler and add object
IScheduler scheduler = factory.GetScheduler();
JobKey firstJobKey = JobKey.Create("FirstJob", "Pipeline");
JobKey secondJobKey = JobKey.Create("SecondJob", "Pipeline");
JobKey thirdJobKey = JobKey.Create("ThirdJob", "Pipeline");
// Create job and trigger
IJobDetail firstJob = JobBuilder.Create<SimpleJob1>()
.WithIdentity(firstJobKey)
//.StoreDurably(true)
.Build();
IJobDetail secondJob = JobBuilder.Create<SimpleJob2>()
.WithIdentity(secondJobKey)
.StoreDurably(true)
.Build();
IJobDetail thirdJob = JobBuilder.Create<SimpleJob3>()
.WithIdentity(thirdJobKey)
.StoreDurably(true)
.Build();
ITrigger firstJobTrigger = TriggerBuilder.Create()
.WithIdentity("Trigger", "Pipeline")
.WithSimpleSchedule(x => x
.WithMisfireHandlingInstructionFireNow()
.WithIntervalInSeconds(5)
.RepeatForever())
.Build();
JobChainingJobListener listener = new JobChainingJobListener("Pipeline Chain");
listener.AddJobChainLink(firstJobKey, secondJobKey);
listener.AddJobChainLink(secondJobKey, thirdJobKey);
scheduler.ListenerManager.AddJobListener(listener, GroupMatcher<JobKey>.GroupEquals("Pipeline"));
// Run it all in chain
scheduler.Start();
scheduler.ScheduleJob(firstJob, firstJobTrigger);
scheduler.AddJob(secondJob, false, true);
scheduler.AddJob(thirdJob, false, true);
//Console.ReadLine();
//scheduler.Shutdown();
//Console.WriteLine("Scheduler shutdown.");
//Console.WriteLine(history);
//Console.ReadLine();
}
}
public class SimpleJob1 : IJob
{
public virtual void Execute(IJobExecutionContext context)
{
JobKey jobKey = context.JobDetail.Key;
//log.InfoFormat("SimpleJob1 says: {0} executing at {1}", jobKey, DateTime.Now.ToString("r"));
Console.WriteLine("作业1: {0} executing at {1}", jobKey, DateTime.Now.ToString("r"));
System.Threading.Thread.Sleep(1000);
}
}
public class SimpleJob2 : IJob
{
public virtual void Execute(IJobExecutionContext context)
{
// This job simply prints out its job name and the
// date and time that it is running
JobKey jobKey = context.JobDetail.Key;
Console.WriteLine("作业2: {0} executing at {1}", jobKey, System.DateTime.Now.ToString("r"));
System.Threading.Thread.Sleep(2000);
}
}
public class SimpleJob3 : IJob
{
public virtual void Execute(IJobExecutionContext context)
{
// This job simply prints out its job name and the
// date and time that it is running
JobKey jobKey = context.JobDetail.Key;
Console.WriteLine("作业3: {0} executing at {1}", jobKey, System.DateTime.Now.ToString("r"));
}
}
}
注意:需要引用Quartz.dll,Common.Logging.dll,Common.Logging.Core.dll
作业引擎quartz.net --- 监听链的更多相关文章
- 简单的quartz 可视化监听管理界面
spring-quartz. 导包.配置,不在此介绍. 简单的quartz管理界面,包括触发器的暂停.恢复.删除.修改(暂无),任务的运行.触发添加.创建,删除. 扩展内容:日志的管理,添加和创建触发 ...
- ORACLE清理、截断监听日志文件(listener.log)
在ORACLE数据库中,如果不对监听日志文件(listener.log)进行截断,那么监听日志文件(listener.log)会变得越来越大,想必不少人听说过关于"LISTENER.LOG日 ...
- 作业调度框架Quartz.NET-现学现用-02-任务监听
原文:作业调度框架Quartz.NET-现学现用-02-任务监听 前言 任务调度系统并不是完美的,它会出现任务执行失败的情况.如果你需要处理任务失败后的逻辑,希望这篇笔记可以为你提供些帮助. Quar ...
- 作业调度框架Quartz.NET-现学现用-02-任务监听 - 简书
原文:作业调度框架Quartz.NET-现学现用-02-任务监听 - 简书 前言 任务调度系统并不是完美的,它会出现任务执行失败的情况.如果你需要处理任务失败后的逻辑,希望这篇笔记可以为你提供些帮助. ...
- Linux对外提供服务 网络操作 端口操作 1.开启服务监听端口 2.设置防火墙,放行访问端口的包 iptables&netfilter 四表五链和通堵策略
主题: Linux服务器上软件提供服务 1.网络操作 2.端口操作 1.网络操作 本机必须能够ping通目标主机(本地虚拟机或者远程主机) 2.端口操作 1.开启服务监听端口 2.设置防火墙,放行访问 ...
- 第十一篇:vue.js监听属性(大作业进行时)
这个知识点急着用所以就跳过<计算属性>先学了 首先理解一下什么是监听:对事件进行监控,也就是当我进行操作(按了按钮之类的事件)时,会有相应的事情发生 上代码 <div id = &q ...
- Liferay7 BPM门户开发之4: Activiti事件处理和监听Event handlers
事件机制从Activiti 5.15开始引入,这非常棒,他可以让你实现委托. 可以通过配置添加事件监听器,也可以通过Runtime API加入注册事件. 所有的事件参数子类型都来自org.activi ...
- quartz2.3.0(九)job任务监听器,监听任务执行前、后、取消手动处理方法
job1任务类 package org.quartz.examples.example9; import java.util.Date; import org.quartz.Job; import o ...
- javaweb监听
监听项目启动 package com.java7115.quartz; import javax.servlet.ServletContextEvent; import javax.servlet.S ...
随机推荐
- Node 多页面请求
//功能:创建web服务器接收客户请求// http://127.0.0.1:8080/index 准备// http://127.0.0.1:8080/news 准备// public/index. ...
- pandas 级联 concat append
连接的一个有用的快捷方式是在Series和DataFrame实例的append方法.这些方法实际上早于concat()方法. 它们沿axis=0连接 #encoding:utf8 import pan ...
- Test Scenarios for a window
1 check if default window size is correct2 check if child window size is correct3 check if there is ...
- python之itemgetter函数:对字典列表进行多键排序
itemgetter函数:对字典列表进行多键排序 from operator import itemgetter list_people = [ {'name': 'Mike', 'age': 22, ...
- LOJ114 k大(xiao)异或和(线性基)
构造线性基后将其消至对任意位至多只有一个元素该位为1.于是就可以贪心了,将k拆成二进制就好.注意check一下是否能异或出0. #include<iostream> #include< ...
- BZOJ4025 二分图(线段树分治+并查集)
之前学了一下线段树分治,这还是第一次写.思想其实挺好理解,即离线后把一个操作影响到的时间段拆成线段树上的区间,并标记永久化.之后一块处理,对于某个节点表示的时间段,影响到他的就是该节点一直到线段树根的 ...
- 【Gym - 101164I】Cubes(dfs,剪枝)
BUPT2017 wintertraining(15) #4 A - I.Cubes Gym - 101164I 题意 将n拆成最少个立方数相加的形式. 题解 根据n的范围,立方数最大不超过400的立 ...
- 几个面试经典算法题Java解答
题目一: public class testClockwiseOutput { //顺时针打印一个矩阵 @Test public void test(){ int[][] num = new int[ ...
- jsp关闭或刷新浏览器(解决浏览器不兼容),请求后台onbeforeunload、onunload
jsp关闭或刷新浏览器(解决浏览器不兼容),请求后台 onbeforeunload.onunload 1.看代码: function test(e) { var json = "退出,清理 ...
- 再次膜拜IE的超强兼容性
今天用firefox和chrome打开几年前写的一个网页,突然发现复选框的“全选”功能失效了. 然后用ie试了一下,竟然正常. 到firefox的错误控制台查看,提示错误: TypeError: id ...