public void TestDequeue_NoJobs() { JobQueue queue = new JobQueue(); IJobTicket req = queue.Dequeue(); Assert.IsNull(req); }
/// <summary> /// Handles the results of a finised job. /// </summary> /// <param name="completeJob">The <see cref="IJobTicket"/> representing /// the finished job.</param> public void HandleResults(IJobTicket completeJob) { foreach (IJobResultsHandler handler in this) { _tryHandle(completeJob, handler); } }
public void TestDequeue_MultipleJobs() { JobQueue queue = new JobQueue(); IJobDefinition d = new DudDefinition(); JobRequest r = new JobRequest(d); JobTicket t = new JobTicket(r, new DudHandler()); queue.Enqueue(t); JobRequest r2 = new JobRequest(d); JobTicket t2 = new JobTicket(r2, new DudHandler()); queue.Enqueue(t2); IJobTicket ta = queue.Dequeue(); Assert.AreEqual(t, ta); Assert.IsTrue(queue.HasPendingJobs); Assert.AreEqual(1, queue.NumberOfJobs); IJobTicket tb = queue.Dequeue(); Assert.AreEqual(t2, tb); Assert.IsFalse(queue.HasPendingJobs); Assert.AreEqual(0, queue.NumberOfJobs); }
/// <summary> /// Initializes a new instance of the <see cref="JobViewModel"/> class. /// </summary> /// <param name="job">The <see cref="IJobTicket"/> representing the job /// presented by this <see cref="JobViewModel"/>.</param> /// <exception cref="ArgumentNullException">job is null</exception> public JobViewModel(IJobTicket job) { if (job == null) { throw new ArgumentNullException("job"); } _estimator = new InputTimeEstimator(job); _estimator.PropertyChanged += _estimatorPropertyChanged; TimeEnqueued = DateTime.Now; Identifier = job.Request.Identifier; Inputs = new ObservableCollection <InputViewModel>(); job.Request.Job .GetInputs() .ForEach(x => Inputs.Add(new InputViewModel(x))); _status = string.Empty; _longStatus = string.Empty; _isRunning = false; _sink = new TicketSink(); _sink.JobCancelled += _onJobCancelled; _sink.JobCompleted += _onJobComplete; _sink.JobError += _onJobError; _sink.JobStarted += _onJobStarted; _sink.InputProcessed += _inputProcessed; _sink.InputStarted += _inputStarted; Ticket = job; Ticket.Sinks.Add(_sink); _updateFromState(); }
/// <summary> /// Attempts to run a single handler /// </summary> /// <param name="ticket">The finished job</param> /// <param name="handler">The job handler</param> private void _tryHandle(IJobTicket ticket, IJobResultsHandler handler) { try { handler.HandleResults(ticket); } catch { } }
/// <summary> /// Handles the results of a finised job. /// </summary> /// <param name="completeJob">The <see cref="IJobTicket"/> representing /// the finished job.</param> public void HandleResults(IJobTicket completeJob) { JobResult result = completeJob.Result; if (result.Result == JobState.Complete) { _saveImages(completeJob.Request.Job.GetInputs(), result.Images); } }
/// <summary> /// Executes the next job in the queue. /// </summary> private void run_next_job() { IJobTicket req = _queue.Dequeue(); if (req.Cancelled == false) { WorkerArgs args = new WorkerArgs(Persister, new PluginPipelineFactory(PluginFactory)); args.Ticket = req; Worker.Work(args); } }
/// <summary> /// Deletes the results of a previously complete job. /// </summary> /// <param name="ticket">The <see cref="IJobTicket"/> representing the /// job to be deleted.</param> /// <returns><c>true</c> if the results associated with the /// <see cref="JobTicket"/> have been deleted.</returns> public bool DeleteResults(IJobTicket ticket) { if (_tickets.Contains(ticket) && ticket is JobTicket) { return(_persister.Delete(((JobTicket)ticket).JobID)); } else { return(false); } }
/// <summary> /// Entry point to the threaded execute functionality /// </summary> private void _execute() { IProcessingService service = Container.Resolve <IProcessingService>(); ObjectJobDefinition d = new ObjectJobDefinition(_source.Pipeline, _filesToInputs()); JobRequest r = new JobRequest(d); r.Identifier = _source.Identifier; IJobTicket t = service.JobManager.EnqueueJob(r); IJobTracker tracker = Container.Resolve <IJobTracker>(); tracker.Add(t, _source.Handler); }
/// <summary> /// Executes the cancellation-handling code determined by this class. /// </summary> /// <param name="ticket">The ticket to cancel</param> /// <returns>true if the cancellation was handled, false otherwise.</returns> private bool _selfHandleCancellation(IJobTicket ticket) { if (_internalCollection.Contains(ticket)) { _internalCollection.Remove(ticket); return(true); } else { return(false); } }
/// <summary> /// Handles the cancellation of the job represented by the ticket. /// </summary> /// <param name="ticket">The <see cref="IJobTicket"/> that has been /// cancelled.</param> /// <returns>true if the request has been handled; false otherwise.</returns> public bool Handle(IJobTicket ticket) { lock ( _cancelPadlock ) { if (_ticket != null) { _cancel = true; } } return(_cancel); }
/// <summary> /// Enqueues a new job to be executed. /// </summary> /// <param name="job">The <see cref="JobRequest"/> detailing the /// job.</param> /// <returns>An <see cref="IJobTicket"/> providing job monitoring and /// result-tracking capabilities.</returns> public IJobTicket EnqueueJob(JobRequest job) { IJobTicket ticket = _processor.Enqueue(job); _tickets.Add(ticket); if (_processor.IsProcessing == false) { _processor.StartProcessing(); } return(ticket); }
/// <summary> /// Enqueues a new job to this <see cref="IJobQueue"/>. /// </summary> /// <param name="req">The <see cref="IJobTicket"/> representing the /// job information.</param> public void Enqueue(IJobTicket req) { if (req == null) { return; } lock (this) { _internalCollection.Add(req); notifyJobAdded(); } }
/// <summary> /// Initializes a new instance of the <see cref="InputTimeEstimator"/> /// class. /// </summary> /// <param name="ticket">The <see cref="IJobTicket"/> used to /// estimate the duration of the job of.</param> /// <exception cref="ArgumentNullException">ticket is null</exception> public InputTimeEstimator(IJobTicket ticket) { if (ticket == null) { throw new ArgumentNullException("ticket"); } _previousDurations = new List <TimeSpan>(); _ticket = ticket; _sink = new TicketSink(); _ticket.Sinks.Add(_sink); _sink.InputStarted += _inputStarted; _sink.InputProcessed += _inputProcessed; }
/// <summary> /// Resolves the <see cref="JobResult"/> for a previously executed job. /// </summary> /// <param name="ticket">The <see cref="IJobTicket"/> representing the /// job.</param> /// <returns>The <see cref="JobResult"/> created through the execution of /// the job represented by the <see cref="IJobTicket"/>.</returns> public JobResult GetResult(IJobTicket ticket) { JobTicket theTicket = ticket as JobTicket; Guid jobID = theTicket.JobID; var results = _persister.Load(jobID); if (results.Any()) { return(new JobResult(results)); } else { return(new JobResult(new ArgumentException("Job results not present"))); } }
public void TestDequeue_OneJob() { JobQueue queue = new JobQueue(); IJobDefinition d = new DudDefinition(); JobRequest r = new JobRequest(d); JobTicket t = new JobTicket(r, new DudHandler()); queue.Enqueue(t); IJobTicket t1 = queue.Dequeue(); Assert.AreEqual(t, t1); Assert.AreEqual(0, queue.NumberOfJobs); Assert.IsFalse(queue.HasPendingJobs); }
/// <summary> /// Dequeues the next job to execute. /// </summary> /// <returns>The <see cref="IJobTicket"/> representing the /// job.</returns> public IJobTicket Dequeue() { lock (this) { if (_internalCollection.Any()) { IJobTicket ticket = _internalCollection.First(); _internalCollection.RemoveAt(0); return(ticket); } else { return(null); } } }
/// <summary> /// Handles the cancellation of the job represented by the ticket. /// </summary> /// <param name="ticket">The <see cref="IJobTicket"/> that has been /// cancelled.</param> /// <returns>true if the request has been handled; false otherwise.</returns> public bool Handle(IJobTicket ticket) { lock (this) { if (_selfHandleCancellation(ticket)) { return(true); } else if (Successor != null) { return(Successor.Handle(ticket)); } else { return(false); } } }
/// <summary> /// Adds a new job to the tracker. /// </summary> /// <param name="ticket">The <see cref="IJobTicket"/> to begin /// tracking.</param> /// <param name="handler">The <see cref="IJobResultsHandler"/> called /// when the job has finished executing.</param> public void Add(IJobTicket ticket, IJobResultsHandler handler) { JobViewModel vm = new JobViewModel(ticket); vm.Handler = handler; switch (ticket.State) { case JobState.InQueue: vm.JobStarted += _jobStarted; vm.JobFinished += _jobFinished; _safeViewModelAction(Pending.Add, vm); break; case JobState.Running: vm.JobStarted += _jobStarted; vm.JobFinished += _jobFinished; Current = vm; break; default: _safeViewModelAction(Finished.Add, vm); break; } }
/// <summary> /// Resolves the <see cref="JobResult"/> for a previously executed job. /// </summary> /// <param name="ticket">The <see cref="IJobTicket"/> representing the /// job.</param> /// <returns>The <see cref="JobResult"/> created through the execution of /// the job represented by the <see cref="IJobTicket"/>.</returns> public JobResult GetResult(IJobTicket ticket) { return(null); }
public bool Handle(IJobTicket ticket) { return(false); }
/// <summary> /// Defines the method to be called when the command is invoked. /// </summary> /// <param name="parameter">Data used by the command. If the command /// does not require data to be passed, this object can be set to /// null.</param> public override void Execute(object parameter) { IJobTicket ticket = parameter as IJobTicket; ticket.Cancel(); }
/// <summary> /// Handles the cancellation of the job represented by the ticket. /// </summary> /// <param name="ticket">The <see cref="IJobTicket"/> that has been /// cancelled.</param> /// <returns>true if the request has been handled; false otherwise.</returns> bool ITicketCancellationHandler.Handle(IJobTicket ticket) { // We don't permit cancelling. return(false); }
public void HandleResults(IJobTicket completeJob) { }
public bool Handle(IJobTicket ticket) { throw new NotImplementedException(); }