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());

最新文章

  1. 关于网络配置和zmp以及json
  2. Tutorial - Deferred Rendering Shadow Mapping 转
  3. 这里整理了基于java平台的常用资源
  4. libjpeg 编译makfile
  5. linux资源使用配置文件 /etc/security/limits.conf和ulimit
  6. 对 JimmyZhang 老师的文章《项目代码风格要求》的一些个人观点
  7. HTML里的id等属性命名需要注意
  8. SQL2008--SQL语句-存储过程-触发器-事务处理-基本语法-函数
  9. sqlite 数据库打开失败
  10. A*寻路算法的探寻与改良(一)
  11. 进程的优先级 与 CFS 进程调度
  12. java学习之异常笔记
  13. AtCoder Beginner Contest 052 ABCD题
  14. C++数据
  15. 时间序列数据库rrd启动
  16. 搭建redis-sentinel(哨兵机制)集群
  17. Lodop的JS模版代码、文档式模版 生成加载赋值博文索引
  18. 【PHP】解析PHP中的函数
  19. java readProperties
  20. git回滚远程仓库代码/错提master分支的恢复

热门文章

  1. PHP curl_close函数
  2. [CSP-S模拟测试]:Miner(欧拉路)
  3. GIT安装包备用地址
  4. 简记 jQuery 插件模板
  5. python and 用法
  6. 热经-北京中地时空数码科技有限公司-研发工程师(WEBGIS方向)
  7. xcode安装pod
  8. SpringBoot 配置相关热启动
  9. 看FPGA面试题时见到被考到的几个逻辑电路
  10. ubuntu16.04安装LNMP(ubuntu+Nginx+mysql+PHP7.0)