博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
作业引擎quartz.net --- 监听链
阅读量:5322 次
发布时间:2019-06-14

本文共 3006 字,大约阅读时间需要 10 分钟。

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

 

转载于:https://www.cnblogs.com/zhangzhi19861216/p/4756610.html

你可能感兴趣的文章
实用Android开发工具和资源精选
查看>>
数据持久化时的小bug
查看>>
bzoj2257
查看>>
http://www.bootcss.com/
查看>>
20145308 《网络对抗》 注入shellcode+Return-to-libc攻击 学习总结
查看>>
查看oracle数据库的连接数以及用户
查看>>
python tkinter GUI绘制,以及点击更新显示图片
查看>>
Spring面试题
查看>>
C语言栈的实现
查看>>
SRM 628 DIV2
查看>>
2018-2019-2 20165314『网络对抗技术』Exp5:MSF基础应用
查看>>
SecureCRT的使用方法和技巧(详细使用教程)
查看>>
自建数据源(RSO2)、及数据源增强
查看>>
2018icpc徐州OnlineA Hard to prepare
查看>>
使用命令创建数据库和表
查看>>
【转】redo与undo
查看>>
安卓当中的线程和每秒刷一次
查看>>
wpf样式绑定 行为绑定 事件关联 路由事件实例
查看>>
TCL:表格(xls)中写入数据
查看>>
Oracle事务
查看>>