针对多个作业:如何描述各个跑批任务之间的顺序,紧前、紧后关系,实现灵活调度。例如: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 --- 监听链的更多相关文章

  1. 简单的quartz 可视化监听管理界面

    spring-quartz. 导包.配置,不在此介绍. 简单的quartz管理界面,包括触发器的暂停.恢复.删除.修改(暂无),任务的运行.触发添加.创建,删除. 扩展内容:日志的管理,添加和创建触发 ...

  2. ORACLE清理、截断监听日志文件(listener.log)

    在ORACLE数据库中,如果不对监听日志文件(listener.log)进行截断,那么监听日志文件(listener.log)会变得越来越大,想必不少人听说过关于"LISTENER.LOG日 ...

  3. 作业调度框架Quartz.NET-现学现用-02-任务监听

    原文:作业调度框架Quartz.NET-现学现用-02-任务监听 前言 任务调度系统并不是完美的,它会出现任务执行失败的情况.如果你需要处理任务失败后的逻辑,希望这篇笔记可以为你提供些帮助. Quar ...

  4. 作业调度框架Quartz.NET-现学现用-02-任务监听 - 简书

    原文:作业调度框架Quartz.NET-现学现用-02-任务监听 - 简书 前言 任务调度系统并不是完美的,它会出现任务执行失败的情况.如果你需要处理任务失败后的逻辑,希望这篇笔记可以为你提供些帮助. ...

  5. Linux对外提供服务 网络操作 端口操作 1.开启服务监听端口 2.设置防火墙,放行访问端口的包 iptables&netfilter 四表五链和通堵策略

    主题: Linux服务器上软件提供服务 1.网络操作 2.端口操作 1.网络操作 本机必须能够ping通目标主机(本地虚拟机或者远程主机) 2.端口操作 1.开启服务监听端口 2.设置防火墙,放行访问 ...

  6. 第十一篇:vue.js监听属性(大作业进行时)

    这个知识点急着用所以就跳过<计算属性>先学了 首先理解一下什么是监听:对事件进行监控,也就是当我进行操作(按了按钮之类的事件)时,会有相应的事情发生 上代码 <div id = &q ...

  7. Liferay7 BPM门户开发之4: Activiti事件处理和监听Event handlers

    事件机制从Activiti 5.15开始引入,这非常棒,他可以让你实现委托. 可以通过配置添加事件监听器,也可以通过Runtime API加入注册事件. 所有的事件参数子类型都来自org.activi ...

  8. quartz2.3.0(九)job任务监听器,监听任务执行前、后、取消手动处理方法

    job1任务类 package org.quartz.examples.example9; import java.util.Date; import org.quartz.Job; import o ...

  9. javaweb监听

    监听项目启动 package com.java7115.quartz; import javax.servlet.ServletContextEvent; import javax.servlet.S ...

随机推荐

  1. BOM嵌套简单写法

    WITHTREE AS( SELECT a.FItemID cfitemid,b.FItemID pfitemid FROM dbo.ICBOMChild a,dbo.ICBOM b WHERE a. ...

  2. java List<String>的初始化

    今天在处理生成excel的时候用到了java的list,但是需要直接赋值固定的几个变量,如果先初始化然后add的方法: List<String> name = new ArrayList( ...

  3. Spring IOC和Spring AOP的实现原理(源码主线流程)

    写在前面 正本文参考了<spring技术内幕>和spring 4.0.5源码.本文只描述原理流程的主线部分,其他比如验证,缓存什么可以具体参考源码理解. Spring IOC 一.容器初始 ...

  4. First Knight UVALive - 4297(优化高斯消元解概率dp)

    题意: 一个矩形区域被分成 m*n 个单元编号为 (1, 1)至 (m, n),左上为 (1, 1),右下为(m, n).给出P(k)i,j,其中 1 ≤ i ≤ m,1 ≤ j ≤ n,1 ≤ k ...

  5. 【POJ 2823】Sliding Window(单调队列/堆)

    BUPT2017 wintertraining(16) #5 D POJ - 2823 题意 给定n,k,求滑窗[i,i+k-1]在(1<=i<=n)的最大值最小值. 题解 单调队列或堆. ...

  6. 删除linux下的指定文件

    要求:删除linux下2天前的指定文件 find 文件问题:在 tmp 目录下有大量包含 picture_* 的临时文件,每天晚上 2:00 对一天前的文件进行清理.之前在 crontab 下跑如下脚 ...

  7. 自学Python2.1-基本数据类型-字符串str(object) 上

    自学Python之路 自学Python2.1-基本数据类型-字符串str(object) 上 字符串是 Python 中最常用的数据类型.我们可以使用引号('或")来创建字符串. 创建字符串 ...

  8. [luogu1373]小a和uim之大逃离【动态规划】

    传送门:https://www.luogu.org/problemnew/show/P1373 定义状态是:\(f[i][j][h][0..1]\)表示在\([i,j]\)两个人相差为h,让某一个人走 ...

  9. 设置outlook 2013 默认的ost路径

    How To Change Default Data File (.OST) Location in Office 2013 To set the default location of an out ...

  10. JDK源码分析(6)ConcurrentHashMap

    JDK版本 ConcurrentHashMap源码分析 table:默认为null,初始化发生在第一次插入操作,默认大小为16的数组,用来存储Node节点数据,扩容时大小总是2的幂次方. nextTa ...