Пример #1
0
        public HttpResponseMessage InvokeTriggeredJob(string jobName, string arguments = null)
        {
            try
            {
                _triggeredJobsManager.InvokeTriggeredJob(jobName, arguments, "External - " + Request.Headers.UserAgent);
                return(Request.CreateResponse(HttpStatusCode.Accepted));
            }
            catch (JobNotFoundException)
            {
                return(Request.CreateResponse(HttpStatusCode.NotFound));
            }
            catch (ConflictException)
            {
                return(CreateErrorResponse(HttpStatusCode.Conflict, Resources.Error_WebJobAlreadyRunning));
            }
            catch (WebJobsStoppedException)
            {
                return(CreateErrorResponse(HttpStatusCode.Conflict, Resources.Error_WebJobsStopped));
            }
            catch
            {
                if (FileSystemHelpers.IsFileSystemReadOnly())
                {
                    // return 503 to ask caller to retry, since ReadOnly file system should be temporary
                    return(Request.CreateResponse(HttpStatusCode.ServiceUnavailable));
                }

                throw;
            }
        }
Пример #2
0
        public HttpResponseMessage InvokeTriggeredJob(string jobName, string arguments = null)
        {
            try
            {
                _triggeredJobsManager.InvokeTriggeredJob(jobName, arguments, "External - " + Request.Headers.UserAgent);

                // Return a 200 in the ARM case, otherwise a 202 can cause it to poll on /run, which we don't support
                // For non-ARM, stay with the 202 to reduce potential impact of change
                return(Request.CreateResponse(ArmUtils.IsArmRequest(Request) ? HttpStatusCode.OK : HttpStatusCode.Accepted));
            }
            catch (JobNotFoundException)
            {
                return(Request.CreateResponse(HttpStatusCode.NotFound));
            }
            catch (ConflictException)
            {
                return(CreateErrorResponse(HttpStatusCode.Conflict, Resources.Error_WebJobAlreadyRunning));
            }
            catch (WebJobsStoppedException)
            {
                return(CreateErrorResponse(HttpStatusCode.Conflict, Resources.Error_WebJobsStopped));
            }
            catch
            {
                if (FileSystemHelpers.IsFileSystemReadOnly())
                {
                    // return 503 to ask caller to retry, since ReadOnly file system should be temporary
                    return(Request.CreateResponse(HttpStatusCode.ServiceUnavailable));
                }

                throw;
            }
        }
Пример #3
0
        private void OnSchedule(TriggeredJobSchedule triggeredJobSchedule)
        {
            bool invoked = false;

            try
            {
                string triggeredJobName = triggeredJobSchedule.TriggeredJob.Name;

                TriggeredJobRun latestTriggeredJobRun = _triggeredJobsManager.GetLatestJobRun(triggeredJobName);
                DateTime        lastRun = latestTriggeredJobRun != null ? latestTriggeredJobRun.StartTime : DateTime.Now.AddMinutes(-1);

                // Make sure we are on schedule
                // Check for the next occurence after the last run (as of now)
                // If it is still now, invoke the triggered job
                // If it's not now (in the future) reschedule the triggered job schedule starting with the last triggered job run
                TimeSpan currentSchedule = triggeredJobSchedule.Schedule.GetNextInterval(lastRun, ignoreMissed: true);
                if (currentSchedule == TimeSpan.Zero)
                {
                    _triggeredJobsManager.InvokeTriggeredJob(triggeredJobName, null, "Schedule - " + triggeredJobSchedule.Schedule);
                    invoked = true;
                }
                else
                {
                    triggeredJobSchedule.Reschedule(lastRun);
                    return;
                }
            }
            catch (ConflictException)
            {
                // Ignore as this is expected when running multiple instances
            }
            catch (Exception ex)
            {
                _traceFactory.GetTracer().TraceError(ex);
            }

            if (invoked)
            {
                triggeredJobSchedule.Logger.LogInformation("WebJob invoked");
            }

            triggeredJobSchedule.Reschedule(DateTime.Now);
        }
Пример #4
0
 public HttpResponseMessage InvokeTriggeredJob(string jobName)
 {
     try
     {
         _triggeredJobsManager.InvokeTriggeredJob(jobName);
         return(Request.CreateResponse(HttpStatusCode.Accepted));
     }
     catch (JobNotFoundException)
     {
         return(Request.CreateResponse(HttpStatusCode.NotFound));
     }
     catch (ConflictException)
     {
         return(CreateErrorResponse(HttpStatusCode.Conflict, Resources.Error_WebJobAlreadyRunning));
     }
     catch (WebJobsStoppedException)
     {
         return(CreateErrorResponse(HttpStatusCode.Conflict, Resources.Error_WebJobsStopped));
     }
 }
Пример #5
0
 public HttpResponseMessage InvokeTriggeredJob(string jobName, string arguments = null)
 {
     try
     {
         _triggeredJobsManager.InvokeTriggeredJob(jobName, arguments, "External - " + Request.Headers.UserAgent);
         return(Request.CreateResponse(HttpStatusCode.Accepted));
     }
     catch (JobNotFoundException)
     {
         return(Request.CreateResponse(HttpStatusCode.NotFound));
     }
     catch (ConflictException)
     {
         return(CreateErrorResponse(HttpStatusCode.Conflict, Resources.Error_WebJobAlreadyRunning));
     }
     catch (WebJobsStoppedException)
     {
         return(CreateErrorResponse(HttpStatusCode.Conflict, Resources.Error_WebJobsStopped));
     }
 }