/// <summary> /// Called by the <see cref="IScheduler" /> after a <see cref="IJobDetail" /> /// has been executed, and be for the associated <see cref="ITrigger" />'s /// <see cref="IOperableTrigger.Triggered" /> method has been called. /// </summary> /// <param name="context"></param> /// <param name="jobException"></param> public virtual void JobWasExecuted(IJobExecutionContext context, JobExecutionException jobException) { ITrigger trigger = context.Trigger; object[] args; if (jobException != null) { string errMsg = jobException.Message; args = new object[] { context.JobDetail.Key.Name, context.JobDetail.Key.Group, SystemTime.UtcNow(), trigger.Key.Name, trigger.Key.Group, trigger.GetPreviousFireTimeUtc(), trigger.GetNextFireTimeUtc(), context.RefireCount, errMsg }; } else { string result = Convert.ToString(context.Result, CultureInfo.InvariantCulture); args = new object[] { context.JobDetail.Key.Name, context.JobDetail.Key.Group, SystemTime.UtcNow(), trigger.Key.Name, trigger.Key.Group, trigger.GetPreviousFireTimeUtc(), trigger.GetNextFireTimeUtc(), context.RefireCount, result }; } }
public DateTime?GetPreviousFireTime(string group, string triggerKey) { DateTime?previousFireTime = null; ITrigger trigger = scheduler.GetTrigger((new TriggerKey(triggerKey, group))); if (trigger.GetPreviousFireTimeUtc().HasValue) { previousFireTime = trigger.GetPreviousFireTimeUtc().Value.DateTime.ToLocalTime(); } return(previousFireTime); }
public Schedule For(ITrigger trigger) { var scheduleId = new Guid(trigger.Key.Name); var jobId = new Guid(trigger.JobKey.Name); var description = trigger.Description; var createdUtc = new DateTime(trigger.JobDataMap.GetLong("CreatedUtc")); var startUtc = trigger.StartTimeUtc.DateTime; var cron = trigger.JobDataMap.ContainsKey("Cron") ? trigger.JobDataMap.GetString("Cron") : null; var nextUtc = trigger.GetNextFireTimeUtc()?.DateTime; var previousUtc = trigger.GetPreviousFireTimeUtc()?.DateTime; var endUtc = trigger.EndTimeUtc?.DateTime; var schedule = Schedule.Init(scheduleId, jobId, description, createdUtc, startUtc); if (!string.IsNullOrEmpty(cron)) { schedule.WithCron(cron); } if (nextUtc.HasValue) { schedule.WithNextUtc(nextUtc.Value); } if (previousUtc.HasValue) { schedule.WithPreviousUtc(previousUtc.Value); } if (endUtc.HasValue) { schedule.WithEndUtc(endUtc.Value); } return(schedule.Build()); }
/// <summary> /// Called by the <see cref="IScheduler" /> when a <see cref="ITrigger" /> /// has fired, it's associated <see cref="IJobDetail" /> /// has been executed, and it's <see cref="IOperableTrigger.Triggered" /> method has been /// called. /// </summary> /// <param name="trigger">The <see cref="ITrigger" /> that was fired.</param> /// <param name="context">The <see cref="IJobExecutionContext" /> that was passed to the /// <see cref="IJob" />'s <see cref="IJob.Execute" /> method.</param> /// <param name="triggerInstructionCode">The result of the call on the <see cref="IOperableTrigger" />'s <see cref="IOperableTrigger.Triggered" /> method.</param> public virtual void TriggerComplete(ITrigger trigger, IJobExecutionContext context, SchedulerInstruction triggerInstructionCode) { string instrCode = "UNKNOWN"; if (triggerInstructionCode == SchedulerInstruction.DeleteTrigger) { instrCode = "DELETE TRIGGER"; } else if (triggerInstructionCode == SchedulerInstruction.NoInstruction) { instrCode = "DO NOTHING"; } else if (triggerInstructionCode == SchedulerInstruction.ReExecuteJob) { instrCode = "RE-EXECUTE JOB"; } else if (triggerInstructionCode == SchedulerInstruction.SetAllJobTriggersComplete) { instrCode = "SET ALL OF JOB'S TRIGGERS COMPLETE"; } else if (triggerInstructionCode == SchedulerInstruction.SetTriggerComplete) { instrCode = "SET THIS TRIGGER COMPLETE"; } object[] args = new object[] { trigger.Key.Name, trigger.Key.Group, trigger.GetPreviousFireTimeUtc(), trigger.GetNextFireTimeUtc(), SystemTime.UtcNow(), context.JobDetail.Key.Name, context.JobDetail.Key.Group, context.RefireCount, triggerInstructionCode, instrCode }; }
public void InitTrigger(ListViewItem Item, ITrigger Trigger) { Item.SubItems.Clear(); TriggerState ts = scheduler.GetScheduler().GetTriggerState(Trigger.Key); Item.Text = ts.ToString(); Item.SubItems.Add(Trigger.Key.Name); Item.SubItems.Add(Trigger.Key.Group); string express = ""; if (Trigger is SimpleTriggerImpl) { express = string.Format("repeate {0} times;repeat-interval {1}ms", (Trigger as ISimpleTrigger).RepeatCount, (Trigger as ISimpleTrigger).RepeatInterval); } else { express = (Trigger as ICronTrigger).CronExpressionString; } Item.SubItems.Add(express); Item.SubItems.Add(FormatTime(Trigger.StartTimeUtc)); Item.SubItems.Add(FormatTime2(Trigger.EndTimeUtc)); Item.SubItems.Add(FormatTime2(Trigger.GetPreviousFireTimeUtc())); Item.SubItems.Add(FormatTime2(Trigger.GetNextFireTimeUtc())); }
private Trigger CreateTrigger(ITrigger poTrigger) { DateTimeOffset? loNextFireTime = poTrigger.GetNextFireTimeUtc(); DateTimeOffset? loPreviousFireTime = poTrigger.GetPreviousFireTimeUtc(); CronTriggerImpl loCronTrigger = poTrigger as CronTriggerImpl; Trigger loTrigger = new Trigger() { Name = poTrigger.Key.Name, Group = poTrigger.Key.Group, TypeName = poTrigger.GetType().FullName, State = this.moScheduler.GetTriggerState(poTrigger.Key).ToString() }; if (loNextFireTime.HasValue) { loTrigger.NextFireTime = loNextFireTime.Value.LocalDateTime; } if (loPreviousFireTime.HasValue) { loTrigger.PreviousFireTime = loPreviousFireTime.Value.LocalDateTime; } if (loCronTrigger != null) { loTrigger.CronExpression = loCronTrigger.CronExpressionString; } return(loTrigger); }
/// <summary> /// Called by the <see cref="IScheduler" /> when a <see cref="IJobDetail" /> /// was about to be executed (an associated <see cref="ITrigger" /> /// has occurred), but a <see cref="ITriggerListener" /> vetoed it's /// execution. /// </summary> /// <seealso cref="JobToBeExecuted"/> public virtual Task JobExecutionVetoed( IJobExecutionContext context, CancellationToken cancellationToken = default) { if (!IsInfoEnabled) { return(Task.CompletedTask); } ITrigger trigger = context.Trigger; object?[] args = { context.JobDetail.Key.Name, context.JobDetail.Key.Group, SystemTime.UtcNow(), trigger.Key.Name, trigger.Key.Group, trigger.GetPreviousFireTimeUtc(), trigger.GetNextFireTimeUtc(), context.RefireCount }; WriteInfo(string.Format(CultureInfo.InvariantCulture, JobWasVetoedMessage, args)); return(Task.CompletedTask); }
public IList <TriggerStatusModel> GetAllTriggerStatus(string groupName) { IScheduler sched = quartzInstance.GetQuartzScheduler(); string[] triggerNames = sched.GetTriggerKeys(GroupMatcher <TriggerKey> .GroupEquals(groupName)).Result.Select(p => p.Name).ToArray();// .GetTriggerNames(groupName); List <TriggerStatusModel> triggerStatuses = new List <TriggerStatusModel>(); foreach (string triggerName in triggerNames) { ITrigger trig = sched.GetTrigger(new TriggerKey(triggerName, groupName)).Result; TriggerState st = sched.GetTriggerState(new TriggerKey(triggerName, groupName)).Result; DateTimeOffset?nextFireTime = trig.GetNextFireTimeUtc(); DateTimeOffset?lastFireTime = trig.GetPreviousFireTimeUtc(); triggerStatuses.Add(new TriggerStatusModel() { TriggerName = triggerName, GroupName = groupName, State = st, NextFireTime = nextFireTime.HasValue?nextFireTime.Value.ToLocalTime().ToString():"", LastFireTime = lastFireTime.HasValue ? lastFireTime.Value.ToLocalTime().ToString() : "", JobName = trig.JobKey.Name }); } return(triggerStatuses); }
public TriggerInfoDto(ITrigger trigger) { TriggerKey = trigger.Key.ToString(); StartTimeUtc = trigger.StartTimeUtc; PrevFireTimeUtc = trigger.GetPreviousFireTimeUtc(); NextFireTimeUtc = trigger.GetNextFireTimeUtc(); MayFireAgain = trigger.GetMayFireAgain(); }
/// <summary> /// Called by the <see cref="IScheduler" /> after a <see cref="IJobDetail" /> /// has been executed, and be for the associated <see cref="ITrigger" />'s /// <see cref="IOperableTrigger.Triggered" /> method has been called. /// </summary> public virtual Task JobWasExecuted( IJobExecutionContext context, JobExecutionException jobException, CancellationToken cancellationToken = default(CancellationToken)) { ITrigger trigger = context.Trigger; object[] args; if (jobException != null) { if (!IsWarnEnabled) { return(TaskUtil.CompletedTask); } string errMsg = jobException.Message; args = new object[] { context.JobDetail.Key.Name, context.JobDetail.Key.Group, SystemTime.UtcNow(), trigger.Key.Name, trigger.Key.Group, trigger.GetPreviousFireTimeUtc(), trigger.GetNextFireTimeUtc(), context.RefireCount, errMsg }; WriteWarning(string.Format(CultureInfo.InvariantCulture, JobFailedMessage, args), jobException); } else { if (!IsInfoEnabled) { return(TaskUtil.CompletedTask); } string result = Convert.ToString(context.Result, CultureInfo.InvariantCulture); args = new object[] { context.JobDetail.Key.Name, context.JobDetail.Key.Group, SystemTime.UtcNow(), trigger.Key.Name, trigger.Key.Group, trigger.GetPreviousFireTimeUtc(), trigger.GetNextFireTimeUtc(), context.RefireCount, result }; WriteInfo(string.Format(CultureInfo.InvariantCulture, JobSuccessMessage, args)); } return(TaskUtil.CompletedTask); }
/// <summary> /// Called by the <see cref="IScheduler" /> when a <see cref="ITrigger" /> /// has misfired. /// <para> /// Consideration should be given to how much time is spent in this method, /// as it will affect all triggers that are misfiring. If you have lots /// of triggers misfiring at once, it could be an issue it this method /// does a lot. /// </para> /// </summary> /// <param name="trigger">The <see cref="ITrigger" /> that has misfired.</param> public virtual void TriggerMisfired(ITrigger trigger) { object[] args = new object[] { trigger.Key.Name, trigger.Key.Group, trigger.GetPreviousFireTimeUtc(), trigger.GetNextFireTimeUtc(), SystemTime.UtcNow(), trigger.JobKey.Name, trigger.JobKey.Group }; }
/// <summary> /// Called by the <see cref="IScheduler" /> when a <see cref="ITrigger" /> /// has fired, and it's associated <see cref="IJobDetail" /> /// is about to be executed. /// <para> /// It is called before the <see cref="VetoJobExecution" /> method of this /// interface. /// </para> /// </summary> /// <param name="trigger">The <see cref="ITrigger" /> that has fired.</param> /// <param name="context">The <see cref="IJobExecutionContext" /> that will be passed to the <see cref="IJob" />'s <see cref="IJob.Execute" /> method.</param> public virtual void TriggerFired(ITrigger trigger, IJobExecutionContext context) { object[] args = new object[] { trigger.Key.Name, trigger.Key.Group, trigger.GetPreviousFireTimeUtc(), trigger.GetNextFireTimeUtc(), SystemTime.UtcNow(), context.JobDetail.Key.Name, context.JobDetail.Key.Group, context.RefireCount }; }
public void UpdateFireTimes(ITrigger trig) { NextFireTimeUtc = trig.GetNextFireTimeUtc(); PreviousFireTimeUtc = trig.GetPreviousFireTimeUtc(); if (NextFireTimeUtc != null) { NextFireTimeTicks = NextFireTimeUtc.Value.UtcTicks; } }
/// <summary> /// Called by the <see cref="IScheduler" /> after a <see cref="IJobDetail" /> /// has been executed, and be for the associated <see cref="ITrigger" />'s /// <see cref="IOperableTrigger.Triggered" /> method has been called. /// </summary> /// <param name="context"></param> /// <param name="jobException"></param> public virtual void JobWasExecuted(IJobExecutionContext context, JobExecutionException jobException) { ITrigger trigger = context.Trigger; object[] args; if (jobException != null) { if (!Log.IsWarnEnabled) { return; } string errMsg = jobException.Message; args = new object[] { context.JobDetail.Key.Name, context.JobDetail.Key.Group, SystemTime.UtcNow(), trigger.Key.Name, trigger.Key.Group, trigger.GetPreviousFireTimeUtc(), trigger.GetNextFireTimeUtc(), context.RefireCount, errMsg }; Log.Warn(String.Format(CultureInfo.InvariantCulture, JobFailedMessage, args), jobException); } else { if (!Log.IsInfoEnabled) { return; } string result = Convert.ToString(context.Result, CultureInfo.InvariantCulture); args = new object[] { context.JobDetail.Key.Name, context.JobDetail.Key.Group, SystemTime.UtcNow(), trigger.Key.Name, trigger.Key.Group, trigger.GetPreviousFireTimeUtc(), trigger.GetNextFireTimeUtc(), context.RefireCount, result }; Log.Info(String.Format(CultureInfo.InvariantCulture, JobSuccessMessage, args)); } }
private static TriggerData GetTriggerData(IScheduler scheduler, ITrigger trigger) { return(new TriggerData(trigger.Key.Name, GetTriggerStatus(trigger, scheduler)) { Group = trigger.Key.Group, StartDate = trigger.StartTimeUtc.DateTime, EndDate = trigger.EndTimeUtc.ToDateTime(), NextFireDate = trigger.GetNextFireTimeUtc().ToDateTime(), PreviousFireDate = trigger.GetPreviousFireTimeUtc().ToDateTime(), TriggerType = TriggerTypeExtractor.GetFor(trigger) }); }
private static async Task <TriggerData> GetTriggerData(IScheduler scheduler, ITrigger trigger) { return(new TriggerData(trigger.Key.Name, await GetTriggerStatus(trigger, scheduler).ConfigureAwait(false)) { GroupName = trigger.Key.Group, StartDate = trigger.StartTimeUtc.DateTime, EndDate = trigger.EndTimeUtc.ToDateTime(), NextFireDate = trigger.GetNextFireTimeUtc().ToDateTime(), PreviousFireDate = trigger.GetPreviousFireTimeUtc().ToDateTime(), TriggerType = TriggerTypeExtractor.GetFor(trigger) }); }
private static TriggerData GetTriggerData(IScheduler scheduler, ITrigger trigger) { return(new TriggerData( trigger.Key.ToString(), trigger.Key.Group, trigger.Key.Name, GetTriggerStatus(trigger, scheduler), trigger.StartTimeUtc.ToUnixTicks(), trigger.EndTimeUtc.ToUnixTicks(), trigger.GetNextFireTimeUtc().ToUnixTicks(), trigger.GetPreviousFireTimeUtc().ToUnixTicks(), TriggerTypeExtractor.GetFor(trigger))); }
public void LogTriggerMisfired(ITrigger trigger) { object[] args = new object[] { trigger.Key.Name, trigger.Key.Group, trigger.GetPreviousFireTimeUtc(), trigger.GetNextFireTimeUtc(), DateTime.Now, trigger.JobKey.Name, trigger.JobKey.Group }; string info = String.Format(CultureInfo.InvariantCulture, triggerMisfiredMessage, args); Console.WriteLine(info); }
/// <summary> /// Called by the <see cref="IScheduler" /> when a <see cref="ITrigger" /> /// has fired, it's associated <see cref="IJobDetail" /> /// has been executed, and it's <see cref="IOperableTrigger.Triggered" /> method has been /// called. /// </summary> /// <param name="trigger">The <see cref="ITrigger" /> that was fired.</param> /// <param name="context">The <see cref="IJobExecutionContext" /> that was passed to the /// <see cref="IJob" />'s <see cref="IJob.Execute" /> method.</param> /// <param name="triggerInstructionCode">The result of the call on the <see cref="IOperableTrigger" />'s <see cref="IOperableTrigger.Triggered" /> method.</param> /// <param name="cancellationToken">The cancellation instruction.</param> public virtual Task TriggerComplete( ITrigger trigger, IJobExecutionContext context, SchedulerInstruction triggerInstructionCode, CancellationToken cancellationToken = default) { if (!IsInfoEnabled) { return(Task.CompletedTask); } string instrCode = "UNKNOWN"; if (triggerInstructionCode == SchedulerInstruction.DeleteTrigger) { instrCode = "DELETE TRIGGER"; } else if (triggerInstructionCode == SchedulerInstruction.NoInstruction) { instrCode = "DO NOTHING"; } else if (triggerInstructionCode == SchedulerInstruction.ReExecuteJob) { instrCode = "RE-EXECUTE JOB"; } else if (triggerInstructionCode == SchedulerInstruction.SetAllJobTriggersComplete) { instrCode = "SET ALL OF JOB'S TRIGGERS COMPLETE"; } else if (triggerInstructionCode == SchedulerInstruction.SetTriggerComplete) { instrCode = "SET THIS TRIGGER COMPLETE"; } object?[] args = { trigger.Key.Name, trigger.Key.Group, trigger.GetPreviousFireTimeUtc(), trigger.GetNextFireTimeUtc(), SystemTime.UtcNow(), context.JobDetail.Key.Name, context.JobDetail.Key.Group, context.RefireCount, triggerInstructionCode, instrCode }; WriteInfo(string.Format(CultureInfo.InvariantCulture, TriggerCompleteMessage, args)); return(Task.CompletedTask); }
private void DoRescheduleJob(IScheduler sched, IMutableTrigger trigger, ITrigger oldTrigger) { // if this is a trigger with default start time we can consider relative scheduling if (oldTrigger != null && trigger.StartTimeUtc - SystemTime.UtcNow() < TimeSpan.FromSeconds(5) && ScheduleTriggerRelativeToReplacedTrigger) { Log.DebugFormat("Using relative scheduling for trigger with key {0}", trigger.Key); var oldTriggerPreviousFireTime = oldTrigger.GetPreviousFireTimeUtc(); trigger.StartTimeUtc = oldTrigger.StartTimeUtc; ((IOperableTrigger)trigger).SetPreviousFireTimeUtc(oldTriggerPreviousFireTime); ((IOperableTrigger)trigger).SetNextFireTimeUtc(trigger.GetFireTimeAfter(oldTriggerPreviousFireTime)); } sched.RescheduleJob(trigger.Key, trigger); }
public static DateTime?GetJobPrevTime(string group, string name) { ITrigger trig = GetJobTrigger(group, name); if (trig == null) { return(null); } DateTimeOffset?next = trig.GetPreviousFireTimeUtc(); if (next.HasValue) { return(next.Value.DateTime); } return(null); }
/// <summary> /// Called by the <see cref="IScheduler" /> when a <see cref="ITrigger" /> /// has fired, and it's associated <see cref="IJobDetail" /> /// is about to be executed. /// <para> /// It is called before the <see cref="VetoJobExecution" /> method of this /// interface. /// </para> /// </summary> /// <param name="trigger">The <see cref="ITrigger" /> that has fired.</param> /// <param name="context">The <see cref="IJobExecutionContext" /> that will be passed to the <see cref="IJob" />'s <see cref="IJob.Execute" /> method.</param> public virtual void TriggerFired(ITrigger trigger, IJobExecutionContext context) { if (!Log.IsInfoEnabled) { return; } object[] args = new object[] { trigger.Key.Name, trigger.Key.Group, trigger.GetPreviousFireTimeUtc(), trigger.GetNextFireTimeUtc(), SystemTime.UtcNow(), context.JobDetail.Key.Name, context.JobDetail.Key.Group, context.RefireCount }; Log.Info(String.Format(CultureInfo.InvariantCulture, TriggerFiredMessage, args)); }
/// <summary> /// Called by the <see cref="IScheduler" /> when a <see cref="ITrigger" /> /// has misfired. /// <para> /// Consideration should be given to how much time is spent in this method, /// as it will affect all triggers that are misfiring. If you have lots /// of triggers misfiring at once, it could be an issue it this method /// does a lot. /// </para> /// </summary> /// <param name="trigger">The <see cref="ITrigger" /> that has misfired.</param> public virtual void TriggerMisfired(ITrigger trigger) { if (!Log.IsInfoEnabled) { return; } object[] args = new object[] { trigger.Key.Name, trigger.Key.Group, trigger.GetPreviousFireTimeUtc(), trigger.GetNextFireTimeUtc(), SystemTime.UtcNow(), trigger.JobKey.Name, trigger.JobKey.Group }; Log.Info(String.Format(CultureInfo.InvariantCulture, TriggerMisfiredMessage, args)); }
public IList <TriggerStatusModel> GetAllTriggerStatus(string groupName) { IScheduler sched = quartzInstance.GetQuartzScheduler(); var groupMatcher = GroupMatcher <TriggerKey> .GroupContains(groupName); var triggerNames = sched.GetTriggerKeys(groupMatcher); // string[] triggerNames= sched.GetTriggerNames(groupName); List <TriggerStatusModel> triggerStatuses = new List <TriggerStatusModel>(); foreach (TriggerKey triggerkey in triggerNames) { ITrigger trig = sched.GetTrigger(triggerkey); TriggerState st = sched.GetTriggerState(triggerkey); var nextFireTimeOffset = trig.GetNextFireTimeUtc(); var lastFireTimeeOffset = trig.GetPreviousFireTimeUtc(); DateTime?nextFireTime = null; if (nextFireTimeOffset.HasValue) { nextFireTime = nextFireTimeOffset.Value.DateTime; } DateTime?lastFireTime = null; if (lastFireTimeeOffset.HasValue) { lastFireTime = lastFireTimeeOffset.Value.DateTime; } triggerStatuses.Add(new TriggerStatusModel() { TriggerName = triggerkey.Name, GroupName = groupName, State = st, NextFireTime = nextFireTime.HasValue?nextFireTime.Value.ToLocalTime().ToString():"", LastFireTime = lastFireTime.HasValue ? lastFireTime.Value.ToLocalTime().ToString() : "", JobName = trig.JobKey.Name }); } return(triggerStatuses); }
protected PersistentTriggerBase(ITrigger trigger, PersistentTriggerState state, string instanceName) : base(EntityType, GetId(instanceName, trigger.Key.Group, trigger.Key.Name), instanceName) { Group = trigger.Key.Group; Name = trigger.Key.Name; JobGroup = trigger.JobKey.Group; JobName = trigger.JobKey.Name; Description = trigger.Description; NextFireTime = trigger.GetNextFireTimeUtc()?.ToUniversalTime(); PreviousFireTime = trigger.GetPreviousFireTimeUtc()?.ToUniversalTime(); State = state; StartTime = trigger.StartTimeUtc; EndTime = trigger.EndTimeUtc; CalendarName = trigger.CalendarName; MisfireInstruction = trigger.MisfireInstruction; Priority = trigger.Priority; JobDataMap = trigger.JobDataMap; }
protected Trigger(ITrigger trigger, TriggerState state, string instanceName) { Id = new TriggerId() { InstanceName = instanceName, Group = trigger.Key.Group, Name = trigger.Key.Name }; JobKey = trigger.JobKey; Description = trigger.Description; NextFireTime = trigger.GetNextFireTimeUtc()?.UtcDateTime; PreviousFireTime = trigger.GetPreviousFireTimeUtc()?.UtcDateTime; State = state; StartTime = trigger.StartTimeUtc.UtcDateTime; EndTime = trigger.EndTimeUtc?.UtcDateTime; CalendarName = trigger.CalendarName; MisfireInstruction = trigger.MisfireInstruction; Priority = trigger.Priority; JobDataMap = trigger.JobDataMap; }
public static TriggerSummary Map(this ITrigger trigger) { return(new TriggerSummary { Key = trigger.Key.Map(), JobKey = trigger.JobKey.Map(), Description = trigger.Description, CalendarName = trigger.CalendarName, StartTimeUtc = trigger.StartTimeUtc, EndTimeUtc = trigger.EndTimeUtc, FinalFireTimeUtc = trigger.FinalFireTimeUtc, HasMillisecondPrecision = trigger.HasMillisecondPrecision, MisfireInstruction = trigger.MisfireInstruction, Priority = trigger.Priority, JobDataMap = trigger.JobDataMap.Map(), MayFireAgain = trigger.GetMayFireAgain(), NextFireTimeUtc = trigger.GetNextFireTimeUtc(), PreviousFireTimeUtc = trigger.GetPreviousFireTimeUtc() }); }
public void JobScheduled(ITrigger trigger) { //throw new NotImplementedException(); Console.WriteLine("---------- JobScheduled"); Console.WriteLine("---------- " + trigger.Key.Name); Console.WriteLine("---------- " + trigger.Key.Group); Console.WriteLine("---------- " + trigger.CalendarName); Console.WriteLine("---------- " + trigger.Description); Console.WriteLine("---------- " + trigger.EndTimeUtc); Console.WriteLine("---------- " + trigger.FinalFireTimeUtc); Console.WriteLine("---------- " + trigger.HasMillisecondPrecision); Console.WriteLine("---------- " + trigger.JobDataMap); Console.WriteLine("---------- " + trigger.JobKey.Name); Console.WriteLine("---------- " + trigger.JobKey.Group); Console.WriteLine("---------- " + trigger.MisfireInstruction); Console.WriteLine("---------- " + trigger.Priority); Console.WriteLine("---------- " + trigger.StartTimeUtc); Console.WriteLine("---------- " + trigger.GetPreviousFireTimeUtc()); Console.WriteLine("---------- " + trigger.GetNextFireTimeUtc()); }
/// <summary> /// Called by the <see cref="IScheduler" /> when a <see cref="ITrigger" /> /// has misfired. /// <para> /// Consideration should be given to how much time is spent in this method, /// as it will affect all triggers that are misfiring. If you have lots /// of triggers misfiring at once, it could be an issue it this method /// does a lot. /// </para> /// </summary> /// <param name="trigger">The <see cref="ITrigger" /> that has misfired.</param> public virtual Task TriggerMisfired(ITrigger trigger) { if (!Log.IsInfoEnabled()) { return(TaskUtil.CompletedTask); } object[] args = { trigger.Key.Name, trigger.Key.Group, trigger.GetPreviousFireTimeUtc(), trigger.GetNextFireTimeUtc(), SystemTime.UtcNow(), trigger.JobKey.Name, trigger.JobKey.Group }; Log.Info(string.Format(CultureInfo.InvariantCulture, TriggerMisfiredMessage, args)); return(TaskUtil.CompletedTask); }
/// <summary> /// Gets all triggers converted to trigger model /// </summary> /// <returns></returns> public static ICollection <TriggerModel> GetAllTriggers() { log.Info("About to get all triggers..."); ICollection <TriggerModel> triggers = new List <TriggerModel>(); log.Info("Finding trigger keys..."); var triggerKeys = scheduler.GetTriggerKeys(GroupMatcher <TriggerKey> .AnyGroup()); if (triggerKeys != null) { log.Info("At list one trigger key was found... Getting triggers"); foreach (TriggerKey key in triggerKeys) { ITrigger trigger = scheduler.GetTrigger(key); if (trigger is ICronTrigger) { triggers.Add(new TriggerModel() { JobName = trigger.JobKey.Name, TriggerName = trigger.Key.Name, TriggerType = trigger.GetType().Name, StartTimeDate = trigger.StartTimeUtc, EndTimeDate = trigger.EndTimeUtc, PreviousFireTimeDate = trigger.GetPreviousFireTimeUtc(), NextFireTimeDate = trigger.GetNextFireTimeUtc(), Message = scheduler.GetJobDetail(trigger.JobKey).JobDataMap.GetString("Message"), MailSubject = scheduler.GetJobDetail(trigger.JobKey).JobDataMap.GetString("MailSubject"), MailBody = scheduler.GetJobDetail(trigger.JobKey).JobDataMap.GetString("MailBody"), JobType = scheduler.GetJobDetail(trigger.JobKey).JobType.Name, CronExpression = ((ICronTrigger)trigger).CronExpressionString }); } } log.Info("Successfuly got all triggers"); } return(triggers); }
public void TriggerComplete(ITrigger trigger, IJobExecutionContext context, SchedulerInstruction triggerInstructionCode) { try { //var executationDuration = (DateTime.UtcNow - trigger.GetPreviousFireTimeUtc()).Value.TotalSeconds; var executionDuration = context.JobRunTime.TotalSeconds; TriggerStatistic triggerStat = new TriggerStatistic() { Group = trigger.Key.Group, JobKey = trigger.JobKey.Name, TriggerKey = trigger.Key.Name, ExecutionDurationInSeconds = executionDuration, StartTime = trigger.GetPreviousFireTimeUtc().Value.DateTime.ToLocalTime(), FinishTime = DateTime.Now }; Sitecore.Diagnostics.Log.Info(String.Format("Job {0} with trigger {1} Completed @ {2} and it took {3} seconds ", triggerStat.JobKey, triggerStat.TriggerKey, DateTime.Now, triggerStat.ExecutionDurationInSeconds), this); string triggerStatProviderType = Settings.GetSetting("Sitecore.QuartzScheduler.TriggerStatisticsStoreProvider"); if (!String.IsNullOrEmpty(triggerStatProviderType)) { var triggerStatsProvider = Activator.CreateInstance(Type.GetType(triggerStatProviderType)) as ITriggerStatisticsStore; triggerStatsProvider.SaveTriggerStatistic(triggerStat); } else { Sitecore.Diagnostics.Log.Warn("Sitecore.QuartzScheuler: Missing App Setting value for Sitecore.QuartzScheduler.TriggerStatisticsStoreProvider", this); } } catch(Exception ex) { Sitecore.Diagnostics.Log.Error("Exception in TriggerComplete: " + ex.Message + Environment.NewLine + ex.StackTrace, this); } }
/// <summary> /// Called by the <see cref="IScheduler" /> when a <see cref="ITrigger" /> /// has fired, it's associated <see cref="IJobDetail" /> /// has been executed, and it's <see cref="IOperableTrigger.Triggered" /> method has been /// called. /// </summary> /// <param name="trigger">The <see cref="ITrigger" /> that was fired.</param> /// <param name="context">The <see cref="IJobExecutionContext" /> that was passed to the /// <see cref="IJob" />'s <see cref="IJob.Execute" /> method.</param> /// <param name="triggerInstructionCode">The result of the call on the <see cref="IOperableTrigger" />'s <see cref="IOperableTrigger.Triggered" /> method.</param> public virtual void TriggerComplete(ITrigger trigger, IJobExecutionContext context, SchedulerInstruction triggerInstructionCode) { string instrCode = "UNKNOWN"; if (triggerInstructionCode == SchedulerInstruction.DeleteTrigger) { instrCode = "DELETE TRIGGER"; } else if (triggerInstructionCode == SchedulerInstruction.NoInstruction) { instrCode = "DO NOTHING"; } else if (triggerInstructionCode == SchedulerInstruction.ReExecuteJob) { instrCode = "RE-EXECUTE JOB"; } else if (triggerInstructionCode ==SchedulerInstruction.SetAllJobTriggersComplete) { instrCode = "SET ALL OF JOB'S TRIGGERS COMPLETE"; } else if (triggerInstructionCode == SchedulerInstruction.SetTriggerComplete) { instrCode = "SET THIS TRIGGER COMPLETE"; } object[] args = new object[] { trigger.Key.Name, trigger.Key.Group, trigger.GetPreviousFireTimeUtc(), trigger.GetNextFireTimeUtc(), SystemTime.UtcNow(), context.JobDetail.Key.Name, context.JobDetail.Key.Group, context.RefireCount, triggerInstructionCode, instrCode }; }
/// <summary> /// Called by the <see cref="IScheduler" /> when a <see cref="ITrigger" /> /// has misfired. /// <para> /// Consideration should be given to how much time is spent in this method, /// as it will affect all triggers that are misfiring. If you have lots /// of triggers misfiring at once, it could be an issue it this method /// does a lot. /// </para> /// </summary> /// <param name="trigger">The <see cref="ITrigger" /> that has misfired.</param> public virtual void TriggerMisfired(ITrigger trigger) { object[] args = new object[] { trigger.Key.Name, trigger.Key.Group, trigger.GetPreviousFireTimeUtc(), trigger.GetNextFireTimeUtc(), SystemTime.UtcNow(), trigger.JobKey.Name, trigger.JobKey.Group }; }
/// <summary> /// Called by the <see cref="IScheduler" /> when a <see cref="ITrigger" /> /// has fired, and it's associated <see cref="IJobDetail" /> /// is about to be executed. /// <para> /// It is called before the <see cref="VetoJobExecution" /> method of this /// interface. /// </para> /// </summary> /// <param name="trigger">The <see cref="ITrigger" /> that has fired.</param> /// <param name="context">The <see cref="IJobExecutionContext" /> that will be passed to the <see cref="IJob" />'s <see cref="IJob.Execute" /> method.</param> public virtual void TriggerFired(ITrigger trigger, IJobExecutionContext context) { object[] args = new object[] { trigger.Key.Name, trigger.Key.Group, trigger.GetPreviousFireTimeUtc(), trigger.GetNextFireTimeUtc(), SystemTime.UtcNow(), context.JobDetail.Key.Name, context.JobDetail.Key.Group, context.RefireCount }; }
/// <summary> /// Called by the <see cref="IScheduler" /> when a <see cref="ITrigger" /> /// has misfired. /// <p> /// Consideration should be given to how much time is spent in this method, /// as it will affect all triggers that are misfiring. If you have lots /// of triggers misfiring at once, it could be an issue it this method /// does a lot. /// </p> /// </summary> /// <param name="trigger">The <see cref="ITrigger" /> that has misfired.</param> public virtual void TriggerMisfired(ITrigger trigger) { if (!Log.IsInfoEnabled) { return; } object[] args = new object[] { trigger.Key.Name, trigger.Key.Group, trigger.GetPreviousFireTimeUtc(), trigger.GetNextFireTimeUtc(), SystemTime.UtcNow(), trigger.JobKey.Name, trigger.JobKey.Group }; Log.Info(String.Format(CultureInfo.InvariantCulture, TriggerMisfiredMessage, args)); }
/// <summary> /// Called by the <see cref="IScheduler" /> when a <see cref="ITrigger" /> /// has fired, and it's associated <see cref="IJobDetail" /> /// is about to be executed. /// <p> /// It is called before the <see cref="VetoJobExecution" /> method of this /// interface. /// </p> /// </summary> /// <param name="trigger">The <see cref="ITrigger" /> that has fired.</param> /// <param name="context">The <see cref="IJobExecutionContext" /> that will be passed to the <see cref="IJob" />'s <see cref="IJob.Execute" /> method.</param> public virtual void TriggerFired(ITrigger trigger, IJobExecutionContext context) { if (!Log.IsInfoEnabled) { return; } object[] args = new object[] { trigger.Key.Name, trigger.Key.Group, trigger.GetPreviousFireTimeUtc(), trigger.GetNextFireTimeUtc(), SystemTime.UtcNow(), context.JobDetail.Key.Name, context.JobDetail.Key.Group, context.RefireCount }; Log.Info(String.Format(CultureInfo.InvariantCulture, TriggerFiredMessage, args)); }
private static TriggerData GetTriggerData(IScheduler scheduler, ITrigger trigger) { return new TriggerData(trigger.Key.Name, GetTriggerStatus(trigger, scheduler)) { GroupName = trigger.Key.Group, StartDate = trigger.StartTimeUtc.DateTime, EndDate = trigger.EndTimeUtc.ToDateTime(), NextFireDate = trigger.GetNextFireTimeUtc().ToDateTime(), PreviousFireDate = trigger.GetPreviousFireTimeUtc().ToDateTime(), TriggerType = TriggerTypeExtractor.GetFor(trigger) }; }