Quartz.Net task scheduling of log (5)

Quartz. Frame and log listeners

1.JobListener task log

Create a new class that inherits 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("已执行");
            });
        }
    }
View Code

Add to Scheduler task unit

 scheduler.ListenerManager.AddJobListener(new CustomJobListener());

2.TriggerListener time strategy logs

Create a new class that inherits 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 the async the Task TriggerFired (ITrigger Trigger, IJobExecutionContext context, a CancellationToken CancellationToken = default ) 
        { 
            the await Task.Run (() => { 

                Console.WriteLine ( " TriggerFired " ); 
            }); 
        } 
        ///  <Summary> 
        /// when Trigger when the execution is excited missed, such as the current time there are many triggers need to be performed, but effective threads in the pool are at work,
         /// then there is likely to trigger a timeout, missed this round is triggered.
        ///  </ Summary> 
        ///  <param name = "Trigger"> </ param> 
        ///  <param name = "CancellationToken"> </ param> 
        ///  <Returns> <
         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;
        }
    }
View Code

Add to Scheduler task unit

 scheduler.ListenerManager.AddJobListener(new CustomJobListener());

3.SchedulerListener 

Create a new class that inherits 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();
        }
    }
View Code

Add to Scheduler task unit

 scheduler.ListenerManager.AddSchedulerListener(new CustomSchedulerListener());

Guess you like

Origin www.cnblogs.com/mi21/p/12091553.html