Пример #1
0
        /// <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);
            }
        }
Пример #2
0
        public HttpResponseMessage GetTriggeredJob(string jobName)
        {
            TriggeredJob triggeredJob = _triggeredJobsManager.GetJob(jobName);

            if (triggeredJob != null)
            {
                return(Request.CreateResponse(HttpStatusCode.OK, triggeredJob));
            }

            return(Request.CreateResponse(HttpStatusCode.NotFound));
        }
Пример #3
0
        public HttpResponseMessage GetTriggeredJob(string jobName)
        {
            TriggeredJob triggeredJob = _triggeredJobsManager.GetJob(jobName);

            if (triggeredJob != null)
            {
                return(Request.CreateResponse(HttpStatusCode.OK, ArmUtils.AddEnvelopeOnArmRequest(triggeredJob, Request)));
            }

            return(Request.CreateResponse(HttpStatusCode.NotFound));
        }
Пример #4
0
        /// <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);
            }
        }