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)的更多相关文章

  1. Spring Quartz实现任务调度

    任务调度 在企业级应用中,经常会制定一些"计划任务",即在某个时间点做某件事情 核心是以时间为关注点,即在一个特定的时间点,系统执行指定的一个操作 任务调度涉及多线程并发.线程池维 ...

  2. Quartz实现任务调度

    一.任务调度概述 在企业级应用中,经常会制定一些"计划任务",即在某个时间点做某件事情,核心是以时间为关注点,即在一个特定的时间点,系统执行指定的一个操作,任务调度涉及多线程并发. ...

  3. quartz.net任务调度:源码及使用文档

    目录: 1.quartz.net任务调度:源码及使用文档 2.quartz.net插件类库封装 前言 前段时间把自己封装quartz.net 类库的过程总结到博客园,有网友想要看一下源码,所以就把源码 ...

  4. 项目ITP(五) spring4.0 整合 Quartz 实现任务调度

    前言 系列文章:[传送门] 项目需求: 二维码推送到一体机上,给学生签到扫描用.然后需要的是 上课前20分钟 ,幸好在帮带我的学长做 p2p 的时候,接触过.自然 quartz 是首选.所以我就配置了 ...

  5. 项目一:第十四天 1.在realm中动态授权 2.Shiro整合ehcache 缓存realm中授权信息 3.动态展示菜单数据 4.Quartz定时任务调度框架—Spring整合javamail发送邮件 5.基于poi实现分区导出

    1 Shiro整合ehCache缓存授权信息 当需要进行权限校验时候:四种方式url拦截.注解.页面标签.代码级别,当需要验证权限会调用realm中的授权方法   Shiro框架内部整合好缓存管理器, ...

  6. Java&Quartz实现任务调度

    目录 Java&Quartz实现任务调度 1.Quartz的作用 2.预备 3.Quartz核心 3.1.Job接口 3.2.JobDetail类 3.3 JobExecutionContex ...

  7. Quartz任务调度 服务日志+log4net打印日志+制作windows服务

    引言 现在许多的项目都需要定时的服务进行支撑,而我们经常用到的定时服务就是Quartz任务调度了.不过我们在使用定时Job进行获取的时候,有时候我们就需要记录一下自定义的日志,甚至我们还会对执行定时J ...

  8. ASP.NET MVC5 实现基于Quartz.NET任务调度

    工作之余.技术?.记是不可能记住的. 只有写点东西 才能维持得了生活这样子的.好早就像写一篇关于任务调度的文章.终究是太懒了 一.Quartz.NET介绍 Quartz.NET是一个强大.开源.轻量的 ...

  9. Quartz.net任务调度

    一.Quartz.net简介 Quartz.net是一个开源的任务调度框架,很多定时任务.调度任务都可以用这个框架,如定时日志等. 二.Quartz.net用途 定时给女朋友发送消息 女朋友生日的时候 ...

随机推荐

  1. jquery自带的排序方法(js也是)

    jquery.sort()   js.sort() <!DOCTYPE html> <html>   <head>     <meta charset=&qu ...

  2. appium介绍和工作原理

    导读 Appium这个听起来既生疏也熟悉的自动化测试工具,比起原生的UiAutomator可能是异常的不起眼,可是却是有自身独当一面的能力,可以完成许多高难度作业,完成UiAutomator不可能完成 ...

  3. Delphi fmx 找不到android设备解决办法

    刚接触到移动开发,很多不熟悉.配置好Android SDK后,​​如果​用模拟器来调试程序的话,那速度会让人崩溃,我用的Nexus7平板​​,插上电脑,开启USB调试,但奇怪在Delphi里就是找不到 ...

  4. php is_file()函数 语法

    php is_file()函数 语法 is_file()函数怎么用? php is_file()函数用于判断给定文件名是否为一个正常的文件,语法是bool is_file ( string $file ...

  5. web uploader 上传大文件总结

    这里只写后端的代码,基本的思想就是,前端将文件分片,然后每次访问上传接口的时候,向后端传入参数:当前为第几块文件,和分片总数 下面直接贴代码吧,一些难懂的我大部分都加上注释了: 上传文件实体类: 看得 ...

  6. codeforces 111C/112E Petya and Spiders

    题目: Petya and Spiders传送门: http://codeforces.com/problemset/problem/111/C http://codeforces.com/probl ...

  7. 【丛林】HTML Table 表格浅谈(边框、隔行变色

    此例子已经包含本文大部分内容,请对照参考.查看代码 > 定义和用法 table标签定义 HTML 表格. 创建表格的四要素:table.tr.th.td <table> 整个表格以& ...

  8. BeautifulSoup的用法

    BeautifulSoup是一个模块,该模块用于接收一个HTML或XML字符串,然后将其进行格式化,之后遍可以使用他提供的方法进行快速查找指定元素,从而使得在HTML或XML中查找指定元素变得简单. ...

  9. nginx启动、关闭、重启及常用的命令

    nginx常用命令 启动:cd /usr/local/nginx/sbin./nginxnginx服务启动后默认的进程号会放在/usr/local/nginx/logs/nginx.pid文件cat ...

  10. SyntaxError: missing ] after element list

    在前端页面js报错,找了很久没找到原因. 后来发现是后台向前端输出json字符串,而前端接收是html格式,需要将后台json字符串改成正常字符串就可以输出,或者通过ajax的方式接收json字符串.