Stop task by id

@param int $taskId Unique task id
@param int $maxRetries Maximum retry count
@return boolean True if success
@throws NotFoundException If no such task found
484368
public function stop($taskId, $maxRetries = 10) {
		$task = $this->read(null, $taskId);

		if (!$task) {
			throw new NotFoundException("Task id=$taskId not found!");
		}

		switch ($task[$this->alias]['status']) {
			case TaskType::FINISHED:
			case TaskType::STOPPING: 
			case TaskType::STOPPED: {
					return true;
				}
			case TaskType::UNSTARTED: {
					return (bool)$this->saveField('status', TaskType::STOPPED);
				}
			case TaskType::RUNNING:
					return (bool)$this->saveField('status', TaskType::STOPPING);
				
			case TaskType::DEFFERED: {
					if ($maxRetries <= 0) {
						return (bool)$this->saveField('status', TaskType::STOPPED);
					}
					sleep(1);
					return $this->stop($taskId, --$maxRetries);
				}
			default:
				return false;
		}
	}
977246
public function getStatusOfTaskWithId($taskId)
    {
        $task = $this->taskRepo->find($taskId);
        if (!($task instanceof Task)) {
            //the task was not found
            return Task::STATUS_GONE;
        }
        return $task->getStatus();
    }
170540
protected function calculateRemainingAttempts($key, $maxAttempts, $retryAfter = null)
    {
        if (is_null($retryAfter)) {
            return $this->limiter->retriesLeft($key, $maxAttempts);
        }

        return 0;
    }
783228
public function runTask($taskId, $context = array())
    {
        $param =  array(
            'actionName' => 'runTask',
            'authPass'   => $this->getConfig('password'),
            'authUser'   => $this->getConfig('login'),
            'taskId'     => $taskId,
            'mode'       => 'synchronous'
        );

        if ($this->getConfig('context') != '' && is_array($this->getConfig('context'))) {
            $context = array_merge($this->getConfig('context'), $context);
        }

        if (!empty($context) && is_array($context)) {
            $param['context'] = $context;
        }

        return $this->getContent($this->doRequest($this->get('?'. $this->getJsonEncoded($param))));
    }
1338490
@Override
	public boolean canRetry(RetryContext context) {
		Throwable t = context.getLastThrowable();
		return (t == null || retryForException(t))
				&& context.getRetryCount() < this.maxAttempts;
	}
633321
public void cancelAllReservations() {
    // Inform jobs which have reserved slots on this tasktracker
    if (jobForFallowMapSlot != null) {
      unreserveSlots(TaskType.MAP, jobForFallowMapSlot);
    }
    if (jobForFallowReduceSlot != null) {
      unreserveSlots(TaskType.REDUCE, jobForFallowReduceSlot);
    }
  }
258244
public function deleteFailedLoginAttempts($maxAge = null)
    {
        $sql = 'DELETE FROM FailedLoginAttempts';
        if ($maxAge) {
            $platform = $this->connection->getDatabasePlatform();
            $sql .= ' WHERE flaTimestamp <= ' . $platform->getDateSubSecondsExpression($platform->getNowExpression(), (int) $maxAge);
        }

        return (int) $this->connection->executeQuery($sql)->rowCount();
    }
554317
public void stopSyncForMount(long mountId) throws InvalidPathException, IOException {
    LOG.debug("Stop sync for mount id {}", mountId);
    if (mFilterMap.containsKey(mountId)) {
      List<Pair<AlluxioURI, MountTable.Resolution>> toBeDeleted = new ArrayList<>();
      for (AlluxioURI uri : mFilterMap.get(mountId)) {
        MountTable.Resolution resolution = resolveSyncPoint(uri);
        if (resolution != null) {
          toBeDeleted.add(new Pair<>(uri, resolution));
        }
      }
      // Calling stopSyncInternal outside of the traversal of mFilterMap.get(mountId) to avoid
      // ConcurrentModificationException
      for (Pair<AlluxioURI, MountTable.Resolution> deleteInfo : toBeDeleted) {
        stopSyncInternal(deleteInfo.getFirst(), deleteInfo.getSecond());
      }
    }
  }
38492
protected function markJobAsFailedIfWillExceedMaxAttempts(Job $job, $maxTries, $e)
    {
        if ($maxTries > 0 && $job->attempts() >= $maxTries) {
            $this->failJob($job, $e);
        }
    }
201402
public Retryer<R> stopAfterDelay(final long delayInMillis) {
        checkArgument(delayInMillis >= 0L, "delayInMillis must be >= 0 but is %d", delayInMillis);
        return withStopStrategy(new StopStrategy() {
            
            @Override public boolean shouldStop(int previousAttemptNumber, long delaySinceFirstAttemptInMillis) {
                return delaySinceFirstAttemptInMillis >= delayInMillis;
            }
        });
    }
418498
public function deleteTaskById($taskId)
    {
        $result = $this->callService('DELETE', self::API_FS_TASK . $taskId);

        return $result->getSuccess();
    }
506147
protected function markJobAsFailedIfAlreadyExceedsMaxAttempts(Job $job, $maxTries)
    {
        if ($maxTries === 0 || $job->attempts() <= $maxTries) {
            return;
        }

        $this->failJob($job, $e = new \RuntimeException('A queued job has been attempted too many times. The job may have previously timed out.'));

        throw $e;
    }
88340
private void retry(String subTaskSpecId, MonitorEntry monitorEntry, TaskStatusPlus lastFailedTaskStatus)
  {
    synchronized (startStopLock) {
      if (running) {
        final SubTaskSpec<T> spec = monitorEntry.spec;
        final T task = spec.newSubTask(monitorEntry.taskHistory.size() + 1);
        log.info("Submitting a new task[%s] for retrying spec[%s]", task.getId(), spec.getId());
        indexingServiceClient.runTask(task);
        incrementNumRunningTasks();

        runningTasks.put(
            subTaskSpecId,
            monitorEntry.withNewRunningTask(
                task,
                indexingServiceClient.getTaskStatus(task.getId()).getStatus(),
                lastFailedTaskStatus
            )
        );
      }
    }
  }
1039185
public static final void assertTaskUncompleted(final String taskId) {
        Validate.notNull(taskId);

        apiCallback.debug(LogMessage.TASK_2, taskId);
        try {
            getTaskInstanceAssertable().taskIsUncompleted(taskId);
        } catch (final AssertionError ae) {
            apiCallback.fail(ae, LogMessage.ERROR_TASK_2, taskId);
        }
    }
647962
protected function getTask($taskId)
    {
        if (!isset($this->tasks[$taskId])) {
            /** @var Queue $taskQueue */
            $taskQueue = $this->getServiceManager()->get(Queue::SERVICE_ID);
            $task = $taskQueue->getTask($taskId);
            if ($task === null) {
                throw new \common_exception_NotFound(__('Task not found'));
            }
            $this->tasks[$taskId] = $task;
        }
        return $this->tasks[$taskId];
    }
1152873
public function stopWorker(int $workerId = null): bool
    {
        if ($this->server) {
            return $this->server->stop($workerId);
        }

        return false;
    }
1101469
public function stopPlayback($playbackId)
    {
        $uri = "playbacks/$playbackId";
        try {
            $this->client->getEndpoint()->delete($uri);
        } catch (RequestException $e) {
            $this->processRequestException($e);
        }
    }