public void CancelJob(string jobId) { IJob job = this.MediaService.MediaContext.Jobs.Where(j => j.Id.Equals(jobId)).FirstOrDefault(); if (job != null) { job.Cancel(); } }
public void ShouldCancelJobAfterSubmission() { IAsset asset = AssetTests.CreateAsset(_mediaContext, _smallWmv, AssetCreationOptions.StorageEncrypted); IMediaProcessor processor = GetMediaProcessor(_mediaContext, WindowsAzureMediaServicesTestConfiguration.MpEncoderName); IJob job = CreateAndSubmitOneTaskJob(_mediaContext, GenerateName("ShouldCancelJobAfterSubmission"), processor, GetWamePreset(processor), asset, TaskOptions.None); WaitForJob(job.Id, JobState.Processing, (string id) => { }); job.Cancel(); WaitForJob(job.Id, JobState.Canceling, (string id) => { }); }
public JsonResult Test(Guid guid) { IJob job = _registry.Find(guid); job?.Cancel(); return(Json(new { Guid = guid, Result = (job != null), Status = job?.State })); }
/// <summary> /// Stops this job timer. /// </summary> /// <param name="cancel">if set to <c>true</c> cancel running job.</param> public void Stop(bool cancel) { JobManager.Current.OnJobStopping(new JobEventArgs(Name, JobAction.Stopping, _id)); StopTimer(); if (cancel && IsBusy && _instance != null) { _instance.Cancel(); } Status = JobStatus.Stopped; }
public void DeleteJob(string jobId) { bool jobDeleted = false; while (!jobDeleted) { IJob theJob = GetJob(jobId); // Check and handle various possible job states. You can // only delete a job whose state is Finished, Error, or Canceled. // You can cancel jobs that are Queued, Scheduled, or Processing, // and then delete after they are canceled. switch (theJob.State) { case JobState.Finished: case JobState.Canceled: theJob.Delete(); jobDeleted = true; Console.WriteLine("Job has been deleted."); break; case JobState.Canceling: Console.WriteLine("Job is cancelling and will be deleted " + "when finished."); Console.WriteLine("Wait while job finishes canceling..."); Thread.Sleep(5000); break; case JobState.Queued: case JobState.Scheduled: case JobState.Processing: theJob.Cancel(); Console.WriteLine("Job is pending or processing and will " + "be canceled, then deleted."); break; case JobState.Error: // Log error as needed. break; default: break; } } }
private void SafeCancel(IJob job) { Asserts <ArgumentNullException> .IsNotNull(job); Log.Verbose("BatchQueue:SafeCancel({0})>", job.Code); try { job.Cancel(); } catch (Exception e) { Log.Error("Job {0} {1}", job.Code, e.Message); } finally { Log.Verbose("BatchQueue:SafeCancel({0})<", job.Code); } }