You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
103 lines
3.5 KiB
103 lines
3.5 KiB
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using Quartz;
|
|
using Quartz.Listener;
|
|
using Quartz.Impl;
|
|
using System.Text;
|
|
|
|
namespace QMTask.Core
|
|
{
|
|
public class JobListener : IJobListener
|
|
{
|
|
public TaskServer MyTaskServer { get; set; }
|
|
|
|
/// <summary>
|
|
/// Get the name of the <see cref="IJobListener" />.
|
|
/// </summary>
|
|
public string Name { get; set; }
|
|
|
|
|
|
/// <summary>
|
|
/// Called by the <see cref="IScheduler" /> when a <see cref="JobDetail" />
|
|
/// is about to be executed (an associated <see cref="Trigger" />
|
|
/// has occured).
|
|
/// <p>
|
|
/// This method will not be invoked if the execution of the Job was vetoed
|
|
/// by a <see cref="ITriggerListener" />.
|
|
/// </p>
|
|
/// </summary>
|
|
/// <seealso cref="JobExecutionVetoed(JobExecutionContext)" />
|
|
public void JobToBeExecuted(IJobExecutionContext context)
|
|
{
|
|
try
|
|
{
|
|
if (MyTaskServer.MonitorInfos.ContainsKey(context.JobDetail.Key) == true)
|
|
{
|
|
MyTaskServer.MonitorInfos[context.JobDetail.Key].Running = true;
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
QMFrameWork.Log.LogManager.LogHelper.Error(
|
|
new QMFrameWork.Log.LogInfo { ClientIP = "localhost", UserName = "admin", Info = "更新监控信息", ErrorInfo = ex });
|
|
throw;
|
|
}
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// Called by the <see cref="IScheduler" /> when a <see cref="JobDetail" />
|
|
/// was about to be executed (an associated <see cref="Trigger" />
|
|
/// has occured), but a <see cref="ITriggerListener" /> vetoed it's
|
|
/// execution.
|
|
/// </summary>
|
|
/// <seealso cref="JobToBeExecuted(JobExecutionContext)" />
|
|
public void JobExecutionVetoed(IJobExecutionContext context)
|
|
{
|
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// Called by the <see cref="IScheduler" /> after a <see cref="JobDetail" />
|
|
/// has been executed, and be for the associated <see cref="Trigger" />'s
|
|
/// <see cref="Trigger.Triggered" /> method has been called.
|
|
/// </summary>
|
|
public void JobWasExecuted(IJobExecutionContext context, JobExecutionException jobException)
|
|
{
|
|
try
|
|
{
|
|
if (MyTaskServer.MonitorInfos.ContainsKey(context.JobDetail.Key) == true)
|
|
{
|
|
MonitorInfo monitor = MyTaskServer.MonitorInfos[context.JobDetail.Key];
|
|
|
|
if (jobException != null)
|
|
{
|
|
monitor.IsNormal = false;
|
|
}
|
|
else
|
|
{
|
|
monitor.IsNormal = true;
|
|
}
|
|
|
|
monitor.LastExecuteResult = context.Result.ToString();
|
|
monitor.LastExecuteTime = DateTime.Now;
|
|
monitor.Running = false;
|
|
|
|
MyTaskServer.MonitorInfos[context.JobDetail.Key] = monitor;
|
|
|
|
//输出
|
|
MyTaskServer.OutputMonitor(monitor);
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
//QMFrameWork.Log.LogManager.LogHelper.Error(
|
|
// new QMFrameWork.Log.LogInfo { ClientIP = "localhost", UserName = "admin", Info = "更新监控信息", ErrorInfo = ex });
|
|
//throw;
|
|
}
|
|
}
|
|
|
|
}
|
|
}
|
|
|