Quartz.Net 任务调度之日志(5)
Quartz.框架的监听器和日志
1.JobListener 任务日志
新建一个类,继承IJobListener
public class CustomJobListener : IJobListener
{
public string Name => "CustomJobListener"; /// <summary>
/// 停止执行
/// </summary>
/// <param name="context"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
public async Task JobExecutionVetoed(IJobExecutionContext context, CancellationToken cancellationToken = default)
{ await Task.Run(()=> { Console.WriteLine("停止执行");
});
}
/// <summary>
/// 待执行
/// </summary>
/// <param name="context"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
public async Task JobToBeExecuted(IJobExecutionContext context, CancellationToken cancellationToken = default)
{
await Task.Run(() => { Console.WriteLine("待执行");
});
}
/// <summary>
/// 已执行
/// </summary>
/// <param name="context"></param>
/// <param name="jobException"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
public async Task JobWasExecuted(IJobExecutionContext context, JobExecutionException jobException, CancellationToken cancellationToken = default)
{
await Task.Run(() => { Console.WriteLine("已执行");
});
}
}
添加到Scheduler 任务单元
scheduler.ListenerManager.AddJobListener(new CustomJobListener());
2.TriggerListener 时间策略日志
新建一个类,继承ITriggerListener
public class CustomTriggerListener : ITriggerListener
{
public string Name => "CustomTriggerListener"; /// <summary>
/// 任务完成时触发
/// </summary>
/// <param name="trigger"></param>
/// <param name="context"></param>
/// <param name="triggerInstructionCode"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
public async Task TriggerComplete(ITrigger trigger, IJobExecutionContext context, SchedulerInstruction triggerInstructionCode, CancellationToken cancellationToken = default)
{
await Task.Run(() => { Console.WriteLine("TriggerComplete");
});
}
/// <summary>
///Trigger被激发 它关联的job即将被运行
/// </summary>
/// <param name="trigger"></param>
/// <param name="context"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
public async Task TriggerFired(ITrigger trigger, IJobExecutionContext context, CancellationToken cancellationToken = default)
{
await Task.Run(() => { Console.WriteLine("TriggerFired");
});
}
/// <summary>
/// 当Trigger错过被激发时执行,比如当前时间有很多触发器都需要执行,但是线程池中的有效线程都在工作,
/// 那么有的触发器就有可能超时,错过这一轮的触发。
/// </summary>
/// <param name="trigger"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
public async Task TriggerMisfired(ITrigger trigger, CancellationToken cancellationToken = default)
{
await Task.Run(()=> {
Console.WriteLine("TriggerMisfired");
});
}
/// <summary>
/// 如果返回true 则取消任务, 返回false 则继续执行
/// </summary>
/// <param name="trigger"></param>
/// <param name="context"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
public async Task<bool> VetoJobExecution(ITrigger trigger, IJobExecutionContext context, CancellationToken cancellationToken = default)
{
return true;
}
}
添加到Scheduler 任务单元
scheduler.ListenerManager.AddJobListener(new CustomJobListener());
3.SchedulerListener
新建一个类,继承ISchedulerListener
/// <summary>
/// 监听一些 动作
/// </summary>
public class CustomSchedulerListener : ISchedulerListener
{
public async Task JobAdded(IJobDetail jobDetail, CancellationToken cancellationToken = default)
{
await Task.Run(() => { Console.WriteLine($"{jobDetail.Key.Name} 添加进来了");
});
} public async Task JobDeleted(JobKey jobKey, CancellationToken cancellationToken = default)
{
await Task.Run(() => { Console.WriteLine($"{jobKey.Name} 删除了");
});
} public Task JobInterrupted(JobKey jobKey, CancellationToken cancellationToken = default)
{
throw new NotImplementedException();
} public Task JobPaused(JobKey jobKey, CancellationToken cancellationToken = default)
{
throw new NotImplementedException();
} public Task JobResumed(JobKey jobKey, CancellationToken cancellationToken = default)
{
throw new NotImplementedException();
} public Task JobScheduled(ITrigger trigger, CancellationToken cancellationToken = default)
{
throw new NotImplementedException();
} public Task JobsPaused(string jobGroup, CancellationToken cancellationToken = default)
{
throw new NotImplementedException();
} public Task JobsResumed(string jobGroup, CancellationToken cancellationToken = default)
{
throw new NotImplementedException();
} public Task JobUnscheduled(TriggerKey triggerKey, CancellationToken cancellationToken = default)
{
throw new NotImplementedException();
} public Task SchedulerError(string msg, SchedulerException cause, CancellationToken cancellationToken = default)
{
throw new NotImplementedException();
} public Task SchedulerInStandbyMode(CancellationToken cancellationToken = default)
{
throw new NotImplementedException();
} public Task SchedulerShutdown(CancellationToken cancellationToken = default)
{
throw new NotImplementedException();
} public Task SchedulerShuttingdown(CancellationToken cancellationToken = default)
{
throw new NotImplementedException();
} public Task SchedulerStarted(CancellationToken cancellationToken = default)
{
throw new NotImplementedException();
} public Task SchedulerStarting(CancellationToken cancellationToken = default)
{
throw new NotImplementedException();
} public Task SchedulingDataCleared(CancellationToken cancellationToken = default)
{
throw new NotImplementedException();
} public Task TriggerFinalized(ITrigger trigger, CancellationToken cancellationToken = default)
{
throw new NotImplementedException();
} public Task TriggerPaused(TriggerKey triggerKey, CancellationToken cancellationToken = default)
{
throw new NotImplementedException();
} public Task TriggerResumed(TriggerKey triggerKey, CancellationToken cancellationToken = default)
{
throw new NotImplementedException();
} public Task TriggersPaused(string triggerGroup, CancellationToken cancellationToken = default)
{
throw new NotImplementedException();
} public Task TriggersResumed(string triggerGroup, CancellationToken cancellationToken = default)
{
throw new NotImplementedException();
}
}
添加到Scheduler 任务单元
scheduler.ListenerManager.AddSchedulerListener(new CustomSchedulerListener());
Quartz.Net 任务调度之日志(5)的更多相关文章
- Spring Quartz实现任务调度
任务调度 在企业级应用中,经常会制定一些"计划任务",即在某个时间点做某件事情 核心是以时间为关注点,即在一个特定的时间点,系统执行指定的一个操作 任务调度涉及多线程并发.线程池维 ...
- Quartz实现任务调度
一.任务调度概述 在企业级应用中,经常会制定一些"计划任务",即在某个时间点做某件事情,核心是以时间为关注点,即在一个特定的时间点,系统执行指定的一个操作,任务调度涉及多线程并发. ...
- quartz.net任务调度:源码及使用文档
目录: 1.quartz.net任务调度:源码及使用文档 2.quartz.net插件类库封装 前言 前段时间把自己封装quartz.net 类库的过程总结到博客园,有网友想要看一下源码,所以就把源码 ...
- 项目ITP(五) spring4.0 整合 Quartz 实现任务调度
前言 系列文章:[传送门] 项目需求: 二维码推送到一体机上,给学生签到扫描用.然后需要的是 上课前20分钟 ,幸好在帮带我的学长做 p2p 的时候,接触过.自然 quartz 是首选.所以我就配置了 ...
- 项目一:第十四天 1.在realm中动态授权 2.Shiro整合ehcache 缓存realm中授权信息 3.动态展示菜单数据 4.Quartz定时任务调度框架—Spring整合javamail发送邮件 5.基于poi实现分区导出
1 Shiro整合ehCache缓存授权信息 当需要进行权限校验时候:四种方式url拦截.注解.页面标签.代码级别,当需要验证权限会调用realm中的授权方法 Shiro框架内部整合好缓存管理器, ...
- Java&Quartz实现任务调度
目录 Java&Quartz实现任务调度 1.Quartz的作用 2.预备 3.Quartz核心 3.1.Job接口 3.2.JobDetail类 3.3 JobExecutionContex ...
- Quartz任务调度 服务日志+log4net打印日志+制作windows服务
引言 现在许多的项目都需要定时的服务进行支撑,而我们经常用到的定时服务就是Quartz任务调度了.不过我们在使用定时Job进行获取的时候,有时候我们就需要记录一下自定义的日志,甚至我们还会对执行定时J ...
- ASP.NET MVC5 实现基于Quartz.NET任务调度
工作之余.技术?.记是不可能记住的. 只有写点东西 才能维持得了生活这样子的.好早就像写一篇关于任务调度的文章.终究是太懒了 一.Quartz.NET介绍 Quartz.NET是一个强大.开源.轻量的 ...
- Quartz.net任务调度
一.Quartz.net简介 Quartz.net是一个开源的任务调度框架,很多定时任务.调度任务都可以用这个框架,如定时日志等. 二.Quartz.net用途 定时给女朋友发送消息 女朋友生日的时候 ...
随机推荐
- .NET面试题集锦①
一.前言部分 文中的问题及答案多收集整理自网络,不保证100%准确,还望斟酌采纳. 1.面向对象的思想主要包括什么? 答:任何事物都可以理解为对象,其主要特征: 继承.封装.多态.特点:代码好维护,安 ...
- django+nginx+uwsgi_cent0s7.4 部署
django+nginx+uwsgi_cent0s7.4 部署 几条命令 # 查看是否有 uwsgi 相关的进程 ps -aux|grep "uwsgi" # 杀死有关 uwsgi ...
- Java Web学习总结(9)学习总结-JSTL
一,JSTL概述 JSTL(JSP Standard Tag Library),JSP标准标签库,可以嵌入在jsp页面中使用标签的形式完成业务逻辑等功能.jstl出现的目的同el一样也是要代替jsp页 ...
- vue和php-前后台交互
vue和php-前后台交互 前端主要代码: <template> <div class="main-member-info"> <form @subm ...
- [CSP-S模拟测试]:platform(后缀数组+二分+线段树)
题目传送门 题目描述 走过奈何桥有一个名叫望乡台的土台,望乡台有个名曰孟婆的老妇人在卖孟婆汤.一生爱恨情仇,一世浮沉得失,都可以随这碗孟婆汤遗忘得干干净净.现在有$n$碗孟婆汤摆成一排,汤的品种不超过 ...
- php中class类文件引入方法汇总
在项目中 总是会用到类文件引入的操作,在此简单总结下: 方法一: 使用 include,require,include_once,require_once. 其中:*_once once意为曾经 ...
- SAS中的Order By - Proc Sort
SAS中的Order By - Proc Sort 1.排序proc sort proc sort在按数据集中某一个变量或几个变量的升序或降序将记录重新排列,并把结果保存在输出数据集中,如果不另外指定 ...
- How To Release and/or Renew IP Addresses on Windows XP | 2000 | NT
Type 'ipconfig' (without the quotes) to view the status of the computer's IP address(es). If the com ...
- [Fw]初探linux中断系统(1)
1. 重要接口 LDD上说,“内核维护了一个中断信号线的注册表,该注册表类似于I/O端口的注册表.模块在使用中断前要先请求一个中断通道(或者中断请求IRQ),然后在使用后释放该通道.” 撇开系统如何遍 ...
- docker--container的port映射
使用nginx为例 先运行nginx [root@localhost ~]# docker run --name web -d nginx Unable to find image 'nginx:la ...