public JobTriggerBase SaveUpdateTrigger(long jobId, JobTriggerBase trigger, out bool hadChanges) { var triggerFromDb = this.storageProvider.GetTriggerById(jobId, trigger.Id); hadChanges = false; if (trigger.IsActive != triggerFromDb.IsActive) { // Activated or deactivated triggerFromDb.IsActive = trigger.IsActive; hadChanges = true; } hadChanges = hadChanges || this.ApplyOtherChanges(triggerFromDb as dynamic, trigger as dynamic); if (hadChanges) { if (trigger is InstantTrigger) { this.storageProvider.Update(jobId, trigger as InstantTrigger); } if (trigger is ScheduledTrigger) { this.storageProvider.Update(jobId, trigger as ScheduledTrigger); } if (trigger is RecurringTrigger) { this.storageProvider.Update(jobId, trigger as RecurringTrigger); } } return(triggerFromDb); }
private bool ApplyBaseChanges(JobTriggerBase fromDb, JobTriggerBase updatedOne) { bool hadChanges = false; if (string.Equals(fromDb.Comment, updatedOne.Comment, StringComparison.Ordinal) == false) { fromDb.Comment = updatedOne.Comment; hadChanges = true; } if (string.Equals(fromDb.UserId, updatedOne.UserId, StringComparison.Ordinal) == false) { fromDb.UserId = updatedOne.UserId; hadChanges = true; } if (string.Equals(fromDb.UserDisplayName, updatedOne.UserDisplayName, StringComparison.Ordinal) == false) { fromDb.UserDisplayName = updatedOne.UserDisplayName; hadChanges = true; } if (string.Equals(fromDb.Parameters, updatedOne.Parameters, StringComparison.Ordinal) == false) { fromDb.Parameters = updatedOne.Parameters; hadChanges = true; } return(hadChanges); }
private JobRun CreateNewJobRun(JobTriggerBase trigger, DateTime dateTime) { var job = this.repository.GetJob(trigger.JobId); var jobRun = this.repository.SaveNewJobRun(job, trigger, dateTime); return(jobRun); }
public JobRun SaveNewJobRun(Job job, JobTriggerBase trigger, DateTime plannedStartDateTimeUtc) { var jobRun = new JobRun { JobId = job.Id, TriggerId = trigger.Id, JobParameters = job.Parameters, InstanceParameters = trigger.Parameters, State = JobRunStates.Scheduled, PlannedStartDateTimeUtc = plannedStartDateTimeUtc }; this.storageProvider.AddJobRun(jobRun); return(jobRun); }
private static void AddTrigger(IJobStorageProvider storage, JobTriggerBase trigger, JobDefinition jobDef, long jobId) { trigger.IsActive = true; trigger.JobId = jobId; Logger.InfoFormat("Adding trigger (type: '{0}' to job '{1}' (JobId: '{2}')", trigger.GetType().Name, jobDef.UniqueName, jobId); var scheduledTrigger = trigger as ScheduledTrigger; if (scheduledTrigger != null) { storage.AddTrigger(jobId, scheduledTrigger); } var recurringTrigger = trigger as RecurringTrigger; if (recurringTrigger != null) { storage.AddTrigger(jobId, recurringTrigger); } }
private void UpdatePlannedJobRun(JobRun plannedNextRun, JobTriggerBase trigger, DateTime calculatedNextRun) { // Is this value in sync with the schedule table? if (plannedNextRun.PlannedStartDateTimeUtc == calculatedNextRun) { Logger.DebugFormat( "The previously planned startdate '{0}' is still correct for JobRun (id: {1}) triggered by trigger with id '{2}' (Type: '{3}', userId: '{4}', userName: '******')", calculatedNextRun, plannedNextRun.Id, trigger.Id, trigger.GetType().Name, trigger.UserId, trigger.UserDisplayName); return; } // Was the change too close before the execution date? var utcNow = this.dateTimeProvider.GetUtcNow(); if (utcNow.AddSeconds(this.configuration.AllowChangesBeforeStartInSec) >= calculatedNextRun) { Logger.WarnFormat( "The planned startdate '{0}' has changed to '{1}'. This change was done too close (less than {2} seconds) to the next planned run and cannot be adjusted", plannedNextRun.PlannedStartDateTimeUtc, calculatedNextRun, this.configuration.AllowChangesBeforeStartInSec); return; } Logger.WarnFormat("The calculated startdate '{0}' has changed to '{1}', the planned jobRun needs to be updated as next step", plannedNextRun.PlannedStartDateTimeUtc, calculatedNextRun); plannedNextRun.PlannedStartDateTimeUtc = calculatedNextRun; this.repository.Update(plannedNextRun); }
private ScheduledPlanItem CreateNew(PlanResult planResult, JobTriggerBase trigger) { var dateTime = planResult.ExpectedStartDateUtc; if (!dateTime.HasValue) { Logger.Warn($"Unable to gather an expected start date for trigger with id {trigger.Id}, (JobId: {trigger.JobId}), skipping."); return(null); } // Create the next occurence from database var newJobRun = this.CreateNewJobRun(trigger, dateTime.Value); // Add to the initial plan var newItem = new ScheduledPlanItem { TriggerId = trigger.Id, Id = newJobRun.Id, PlannedStartDateTimeUtc = newJobRun.PlannedStartDateTimeUtc }; return(newItem); }
private bool IsSame(JobTriggerBase left, JobTriggerBase right) { return(false); }