public TriggeredJobSchedule(TriggeredJob triggeredJob, Action<TriggeredJobSchedule> onSchedule, TriggeredJobSchedulerLogger logger) { TriggeredJob = triggeredJob; _onSchedule = onSchedule; Logger = logger; _timer = new Timer(OnTimer, triggeredJob, Timeout.Infinite, Timeout.Infinite); }
public TriggeredJobSchedule(TriggeredJob triggeredJob, Action <TriggeredJobSchedule> onSchedule, TriggeredJobSchedulerLogger logger) { TriggeredJob = triggeredJob; _onSchedule = onSchedule; Logger = logger; _timer = new Timer(OnTimer, triggeredJob, Timeout.Infinite, Timeout.Infinite); }
/// <summary> /// Process triggered job schedule when the settings.job file changed /// </summary> private void OnJobChanged(string jobName) { TriggeredJobSchedule triggeredJobSchedule; _triggeredJobsSchedules.TryGetValue(jobName, out triggeredJobSchedule); TriggeredJob triggeredJob = _triggeredJobsManager.GetJob(jobName); if (triggeredJob != null) { string cronExpression = triggeredJob.Settings != null?triggeredJob.Settings.GetSchedule() : null; if (cronExpression != null) { var logger = new TriggeredJobSchedulerLogger(triggeredJob.Name, _environment, _traceFactory); Schedule schedule = null; // before init schedule, check site SKU if site is allowed to have scheduled WebJob if (string.Equals(_settings.GetWebSiteSku(), Constants.BasicSKU, StringComparison.OrdinalIgnoreCase)) { logger.LogInformation(string.Format(CultureInfo.InvariantCulture, "'{0}' tier website doesn`t support scheduled WebJob.", Constants.BasicSKU)); } else { schedule = Schedule.BuildSchedule(cronExpression, logger); } if (schedule != null) { if (triggeredJobSchedule == null) { triggeredJobSchedule = new TriggeredJobSchedule(triggeredJob, OnSchedule, logger); _triggeredJobsSchedules[jobName] = triggeredJobSchedule; } DateTime lastRun = triggeredJob.LatestRun != null ? triggeredJob.LatestRun.StartTime : DateTime.MinValue; // DateTIme.Min if triggered job was never run. triggeredJobSchedule.Reschedule(lastRun, schedule); return; } } } if (triggeredJobSchedule != null) { _traceFactory.GetTracer().Trace("Removing schedule for triggered WebJob {0}".FormatCurrentCulture(jobName)); triggeredJobSchedule.Logger.LogInformation("Removing current schedule from WebJob"); triggeredJobSchedule.Dispose(); _triggeredJobsSchedules.Remove(jobName); } }
/// <summary> /// Process triggered job schedule when the settings.job file changed /// </summary> private void OnJobChanged(string jobName) { TriggeredJobSchedule triggeredJobSchedule; _triggeredJobsSchedules.TryGetValue(jobName, out triggeredJobSchedule); TriggeredJob triggeredJob = _triggeredJobsManager.GetJob(jobName); if (triggeredJob != null) { string cronExpression = triggeredJob.Settings != null ? triggeredJob.Settings.GetSchedule() : null; if (cronExpression != null) { var logger = new TriggeredJobSchedulerLogger(triggeredJob.Name, _environment, _traceFactory); Schedule schedule = null; // before init schedule, check site SKU if site is allowed to have scheduled WebJob if (string.Equals(_settings.GetWebSiteSku(), Constants.BasicSKU, StringComparison.OrdinalIgnoreCase)) { logger.LogInformation(string.Format(CultureInfo.InvariantCulture, "'{0}' tier website doesn`t support scheduled WebJob.", Constants.BasicSKU)); } else { schedule = Schedule.BuildSchedule(cronExpression, logger); } if (schedule != null) { if (triggeredJobSchedule == null) { triggeredJobSchedule = new TriggeredJobSchedule(triggeredJob, OnSchedule, logger); _triggeredJobsSchedules[jobName] = triggeredJobSchedule; } DateTime lastRun = triggeredJob.LatestRun != null ? triggeredJob.LatestRun.StartTime : DateTime.MinValue; // DateTIme.Min if triggered job was never run. triggeredJobSchedule.Reschedule(lastRun, schedule); return; } } } if (triggeredJobSchedule != null) { _traceFactory.GetTracer().Trace("Removing schedule for triggered WebJob {0}".FormatCurrentCulture(jobName)); triggeredJobSchedule.Logger.LogInformation("Removing current schedule from WebJob"); triggeredJobSchedule.Dispose(); _triggeredJobsSchedules.Remove(jobName); } }
public static Schedule BuildSchedule(string cronExpression, TriggeredJobSchedulerLogger logger) { try { var crontabSchedule = CrontabSchedule.Parse(cronExpression, new CrontabSchedule.ParseOptions() {IncludingSeconds = true}); return crontabSchedule != null ? new Schedule(crontabSchedule, logger) : null; } catch (Exception ex) { logger.LogError("Failed to parse schedule \"{0}\". Error: {1}".FormatCurrentCulture(cronExpression, ex.Message)); return null; } }
/// <summary> /// Process triggered job schedule when the settings.job file changed /// </summary> private void OnJobChanged(string jobName) { TriggeredJobSchedule triggeredJobSchedule; _triggeredJobsSchedules.TryGetValue(jobName, out triggeredJobSchedule); TriggeredJob triggeredJob = _triggeredJobsManager.GetJob(jobName); if (_settings.IsWebJobsScheduleDisabled()) { _traceFactory.GetTracer().Trace("All WebJobs schedules have been disabled via WEBJOBS_DISABLE_SCHEDULE"); } else if (triggeredJob != null) { string cronExpression = triggeredJob.Settings != null?triggeredJob.Settings.GetSchedule() : null; if (cronExpression != null) { var logger = new TriggeredJobSchedulerLogger(triggeredJob.Name, _environment, _traceFactory); Schedule schedule = Schedule.BuildSchedule(cronExpression, logger); if (schedule != null) { if (triggeredJobSchedule == null) { triggeredJobSchedule = new TriggeredJobSchedule(triggeredJob, OnSchedule, logger, _analytics); _triggeredJobsSchedules[jobName] = triggeredJobSchedule; } DateTime lastRun = triggeredJob.LatestRun != null ? triggeredJob.LatestRun.StartTime : DateTime.MinValue; // DateTIme.Min if triggered job was never run. triggeredJobSchedule.Reschedule(lastRun, schedule); return; } } } if (triggeredJobSchedule != null) { _traceFactory.GetTracer().Trace("Removing schedule for triggered WebJob {0}".FormatCurrentCulture(jobName)); triggeredJobSchedule.Logger.LogInformation("Removing current schedule from WebJob"); triggeredJobSchedule.Dispose(); _triggeredJobsSchedules.Remove(jobName); } }
public static Schedule BuildSchedule(string cronExpression, TriggeredJobSchedulerLogger logger) { try { var crontabSchedule = CrontabSchedule.Parse(cronExpression, new CrontabSchedule.ParseOptions() { IncludingSeconds = true }); return(crontabSchedule != null ? new Schedule(crontabSchedule, logger) : null); } catch (Exception ex) { logger.LogError("Failed to parse schedule \"{0}\". Error: {1}".FormatCurrentCulture(cronExpression, ex.Message)); return(null); } }
/// <summary> /// Process triggered job schedule when the settings.job file changed /// </summary> private void OnJobChanged(string jobName) { TriggeredJobSchedule triggeredJobSchedule; _triggeredJobsSchedules.TryGetValue(jobName, out triggeredJobSchedule); TriggeredJob triggeredJob = _triggeredJobsManager.GetJob(jobName); if (triggeredJob != null) { string cronExpression = triggeredJob.Settings != null ? triggeredJob.Settings.GetSchedule() : null; if (cronExpression != null) { var logger = new TriggeredJobSchedulerLogger(triggeredJob.Name, _environment, _traceFactory); Schedule schedule = Schedule.BuildSchedule(cronExpression, logger); if (schedule != null) { if (triggeredJobSchedule == null) { triggeredJobSchedule = new TriggeredJobSchedule(triggeredJob, OnSchedule, logger, _analytics); _triggeredJobsSchedules[jobName] = triggeredJobSchedule; } DateTime lastRun = triggeredJob.LatestRun != null ? triggeredJob.LatestRun.StartTime : DateTime.MinValue; // DateTIme.Min if triggered job was never run. triggeredJobSchedule.Reschedule(lastRun, schedule); return; } } } if (triggeredJobSchedule != null) { _traceFactory.GetTracer().Trace("Removing schedule for triggered WebJob {0}".FormatCurrentCulture(jobName)); triggeredJobSchedule.Logger.LogInformation("Removing current schedule from WebJob"); triggeredJobSchedule.Dispose(); _triggeredJobsSchedules.Remove(jobName); } }
private Schedule(CrontabSchedule crontabSchedule, TriggeredJobSchedulerLogger logger) { _crontabSchedule = crontabSchedule; _logger = logger; }