Quartz.Net 任务调度之日志(5)
标签:gif man mis closed string sum manage complete schedule
Quartz.框架的监听器和日志
1.JobListener 任务日志
新建一个类,继承IJobListener
public class CustomJobListener : IJobListener
{
public string Name => "CustomJobListener";
///
/// 停止执行
///
///
///
///
public async Task JobExecutionVetoed(IJobExecutionContext context, CancellationToken cancellationToken = default)
{
await Task.Run(()=> {
Console.WriteLine("停止执行");
});
}
///
/// 待执行
///
///
///
///
public async Task JobToBeExecuted(IJobExecutionContext context, CancellationToken cancellationToken = default)
{
await Task.Run(() => {
Console.WriteLine("待执行");
});
}
///
/// 已执行
///
///
///
///
///
public async Task JobWasExecuted(IJobExecutionContext context, JobExecutionException jobException, CancellationToken cancellationToken = default)
{
await Task.Run(() => {
Console.WriteLine("已执行");
});
}
}
View Code
添加到Scheduler 任务单元
scheduler.ListenerManager.AddJobListener(new CustomJobListener());
2.TriggerListener 时间策略日志
新建一个类,继承ITriggerListener
public class CustomTriggerListener : ITriggerListener
{
public string Name => "CustomTriggerListener";
///
/// 任务完成时触发
///
///
///
///
///
///
public async Task TriggerComplete(ITrigger trigger, IJobExecutionContext context, SchedulerInstruction triggerInstructionCode, CancellationToken cancellationToken = default)
{
await Task.Run(() => {
Console.WriteLine("TriggerComplete");
});
}
///
///Trigger被激发 它关联的job即将被运行
///
///
///
///
///
public async Task TriggerFired(ITrigger trigger, IJobExecutionContext context, CancellationToken cancellationToken = default)
{
await Task.Run(() => {
Console.WriteLine("TriggerFired");
});
}
///
/// 当Trigger错过被激发时执行,比如当前时间有很多触发器都需要执行,但是线程池中的有效线程都在工作,
/// 那么有的触发器就有可能超时,错过这一轮的触发。
///
///
///
///
public async Task TriggerMisfired(ITrigger trigger, CancellationToken cancellationToken = default)
{
await Task.Run(()=> {
Console.WriteLine("TriggerMisfired");
});
}
///
/// 如果返回true 则取消任务, 返回false 则继续执行
///
///
///
///
///
public async Taskbool> VetoJobExecution(ITrigger trigger, IJobExecutionContext context, CancellationToken cancellationToken = default)
{
return true;
}
}
View Code
添加到Scheduler 任务单元
scheduler.ListenerManager.AddJobListener(new CustomJobListener());
3.SchedulerListener
新建一个类,继承ISchedulerListener
///
/// 监听一些 动作
///
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();
}
}
View Code
添加到Scheduler 任务单元
scheduler.ListenerManager.AddSchedulerListener(new CustomSchedulerListener());
Quartz.Net 任务调度之日志(5)
标签:gif man mis closed string sum manage complete schedule
原文地址:https://www.cnblogs.com/mi21/p/12091553.html
评论