public IHttpActionResult TryCancelJob(Guid jobId)
        {
            if (jobId == Guid.Empty)
            {
                return(BadRequest(JobIdIsInvalid));
            }

            Logger.InfoWithLineNumber(_workerWrapper.WhoamI +
                                      " : Received Cancel request. jobId: " + jobId);

            var currentJob = _workerWrapper.GetCurrentMessageToProcess();

            if (currentJob == null || currentJob.JobId != jobId)
            {
                Logger.WarningWithLineNumber(_workerWrapper.WhoamI +
                                             ": Could not cancel job since job not found on this node. Manager sent job ( jobId ) : ( " +
                                             jobId + " )");

                return(NotFound());
            }

            if (_workerWrapper.IsCancellationRequested)
            {
                return(Conflict());
            }

            _workerWrapper.CancelJob(jobId);

            if (_workerWrapper.IsCancellationRequested)
            {
                return(Ok());
            }

            return(NotFound());
        }
Exemple #2
0
        public void ShouldNotThrowWhenCancellingAlreadyCancelledJob()
        {
            _workerWrapper = new WorkerWrapper(new LongRunningInvokeHandlerFake(),
                                               _nodeConfigurationFake,
                                               _nodeStartupNotification,
                                               _pingToManagerFake,
                                               _sendJobDoneTimer,
                                               _sendJobCanceledTimer,
                                               _sendJobFaultedTimer,
                                               _trySendJobDetailToManagerTimer,
                                               _jobDetailSender);
            _workerWrapper.ValidateStartJob(_jobDefinition);
            _workerWrapper.StartJob(_jobDefinition);
            _workerWrapper.CancelJob(_jobDefinition.JobId);

            _workerWrapper.CancelJob(_jobDefinition.JobId);

            Assert.IsTrue(_workerWrapper.IsCancellationRequested);
        }
		public void ShouldNotThrowWhenCancellingAlreadyCancelledJob()
		{
			_workerWrapper = new WorkerWrapper(new LongRunningInvokeHandlerFake(),
			                                   _nodeConfigurationFake,
			                                   _nodeStartupNotification,
			                                   _pingToManagerFake,
			                                   _sendJobDoneTimer,
			                                   _sendJobCanceledTimer,
			                                   _sendJobFaultedTimer,
											   _trySendJobDetailToManagerTimerFake);

			_workerWrapper.StartJob(_jobDefinition);
			_workerWrapper.CancelJob(_jobDefinition.JobId);

			_workerWrapper.CancelJob(_jobDefinition.JobId);

			Assert.IsTrue(_workerWrapper.IsCancellationRequested);
		}