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