Checks whether task must be skipped and decreases the counter in that case.
772669
def apply_async(self, args=None, kwargs=None, **options):
        
        key = self._get_cache_key(args, kwargs)
        counter, penalty = cache.get(key, (0, 0))
        if not counter:
            return super(PenalizedBackgroundTask, self).apply_async(args=args, kwargs=kwargs, **options)

        cache.set(key, (counter - 1, penalty), self.CACHE_LIFETIME)
        logger.info('The task %s will not be executed due to the penalty.' % self.name)
        return self.AsyncResult(options.get('task_id') or str(uuid4()))
663323
public boolean removeTaskByTaskId(String taskId, boolean isInterrupt) {
        ScheduledFuture<?> future = runningTask.get(taskId);
        boolean flag = future.cancel(isInterrupt);
        if (flag) {
            runningTask.remove(taskId);
        }
        return flag;
    }
654543
def _canceling_task(self, backend):
        
        with self.backend_mutex:
            self.backends[backend] -= 1
            self.task_counter[backend] -= 1
1197158
private void checkForDeadTask(Tenant tenant, TaskRecord taskRecord) {
        Calendar lastReport = taskRecord.getTime(TaskRecord.PROP_PROGRESS_TIME);
        if (lastReport == null) {
            lastReport = taskRecord.getTime(TaskRecord.PROP_START_TIME);
            if (lastReport == null) {
                return; // corrupt/incomplete task record
            }
        }
        long minsSinceLastActivity = (System.currentTimeMillis() - lastReport.getTimeInMillis()) / (1000 * 60);
        if (isOurActiveTask(tenant, taskRecord.getTaskID())) {
            checkForHungTask(tenant, taskRecord, minsSinceLastActivity);
        } else {
            checkForAbandonedTask(tenant, taskRecord, minsSinceLastActivity);
        }
    }
1206336
private boolean schedule(Task task) {
        int index = bufferIndex();
        int buffered = bufferLengths.incrementAndGet(index);

        if (task.isWrite()) {
            buffers[index].add(task);
            drainStatus.set(REQUIRED);
            return false;
        }

        // A buffer may discard a read task if its length exceeds a tolerance level
        if (buffered <= MAXIMUM_BUFFER_SIZE) {
            buffers[index].add(task);
            return (buffered <= BUFFER_THRESHOLD);
        } else { // not optimized for fail-safe scenario
            bufferLengths.decrementAndGet(index);
            return false;
        }
    }
179016
@Service
    public void skipTaskFromWorkflow(String workflowId, String taskReferenceName,
                                     SkipTaskRequest skipTaskRequest) {
        workflowExecutor.skipTaskFromWorkflow(workflowId, taskReferenceName, skipTaskRequest);
    }
596887
boolean takeTaskPermit()
    {
        while (true)
        {
            long current = permits.get();
            int taskPermits = taskPermits(current);
            if (taskPermits == 0)
                return false;
            if (permits.compareAndSet(current, updateTaskPermits(current, taskPermits - 1)))
            {
                if (taskPermits == maxTasksQueued && hasRoom.hasWaiters())
                    hasRoom.signalAll();
                return true;
            }
        }
    }
1293708
boolean canBeSpeculated(long currentTime) {
    if (skipping || !isRunnable() || !isRunning() || 
        completes != 0 || isOnlyCommitPending() ||
        activeTasks.size() > MAX_TASK_EXECS) {
      if (isMapTask() ? job.shouldLogCannotspeculativeMaps() :
            job.shouldLogCannotspeculativeReduces()) {
           LOG.info("Task "+ getTIPId() + " cannot be speculated because of " 
               + "skipping = "+ skipping + " isRunnable() = "+ isRunnable() 
               + " isRunning() = "+ isRunning() + " completes = " + completes
               + " isOnlyCommitPending() = "+ isOnlyCommitPending()  
               + " activetask-size = "+ activeTasks.size() 
               + " MAX_TASK_EXECS = " + MAX_TASK_EXECS);
      }
      return false;
    }

    if (isSpeculativeForced()) {
      return true;
    }

    // no speculation for first few seconds
    if (currentTime - lastDispatchTime < speculativeLag) {
      if (isMapTask() ? job.shouldLogCannotspeculativeMaps() :
            job.shouldLogCannotspeculativeReduces()) {
           LOG.info("Task "+ getTIPId() + " cannot be speculated because of "
               + "no speculation for first few seconds");
      }
      return false;
    }

    // if the task is making progress fast enough to complete within
    // the acceptable duration allowed for each task - do not speculate
    if ((maxProgressRateForSpeculation > 0) &&
        (progressRate > maxProgressRateForSpeculation)) {
      if (isMapTask() ? job.shouldLogCannotspeculativeMaps() :
            job.shouldLogCannotspeculativeReduces()) {
           LOG.info("Task "+ getTIPId() +" cannot be speculated because "
               + "the task progress rate is fast enough to complete."
               + " maxProgressRateForSpeculation = " 
               + maxProgressRateForSpeculation
               + " and progressRate = " + progressRate);
      }
      return false;
    }

    if (isMapTask() ? job.shouldSpeculateAllRemainingMaps() :
                      job.shouldSpeculateAllRemainingReduces()) {
      if (LOG.isDebugEnabled()) {
        LOG.debug("Speculate " + getTIPId() +
            " because the job is almost finished");
      }
      return true;
    }
    if (useProcessingRateForSpeculation) {
      return canBeSpeculatedUsingProcessingRate(currentTime);
    } else {
      return canBeSpeculatedUsingProgressRate(currentTime);
    }
  }
340401
private void checkForDeadTenantTasks(Tenant tenant) {
        m_logger.debug("Checking tenant {} for abandoned tasks", tenant);
        try {
            for(DRow row: DBService.instance(tenant).getAllRows(TaskManagerService.TASKS_STORE_NAME)) {
                TaskRecord taskRecord = buildTaskRecord(row.getKey(), row.getAllColumns(1024).iterator());
                if (taskRecord.getStatus() == TaskStatus.IN_PROGRESS) {
                    checkForDeadTask(tenant, taskRecord);
                }
            }
        } catch (Throwable e) {
            m_logger.warn("Unable to check tenant '{}' for dead tasks: {}", tenant.getName(), e.toString());
        }
    }
161644
def _has_skip(self, msg):
        '''
        
        '''
        for skip in self.skips:
            if re.search(skip, msg):
                return True
        return False
391295
void cancelTasklet(final boolean mayInterruptIfRunning, final int taskletId) {
    lock.lock();
    try {
      // This is not ideal since we are using a linear time search on all the workers.
      final String workerId = getWhereTaskletWasScheduledTo(taskletId);
      if (workerId == null) {
        // launchTasklet called but not yet running.
        taskletsToCancel.add(taskletId);
        return;
      }

      if (mayInterruptIfRunning) {
        LOG.log(Level.FINE, "Cancelling running Tasklet with ID {0}.", taskletId);
        runningWorkers.get(workerId).cancelTasklet(taskletId);
      }
    } finally {
      lock.unlock();
    }
  }
301523
@VisibleForTesting
  void checkSegmentsAndSubmitTasks()
  {
    synchronized (taskLock) {
      List<Interval> intervalsToRemove = new ArrayList<>();
      for (Map.Entry<Interval, HadoopIndexTask> entry : runningTasks.entrySet()) {
        Optional<TaskStatus> taskStatus = taskStorage.getStatus(entry.getValue().getId());
        if (!taskStatus.isPresent() || !taskStatus.get().isRunnable()) {
          intervalsToRemove.add(entry.getKey());
        }
      }
      for (Interval interval : intervalsToRemove) {
        runningTasks.remove(interval);
        runningVersion.remove(interval);
      }

      if (runningTasks.size() == maxTaskCount) {
        //if the number of running tasks reach the max task count, supervisor won't submit new tasks.
        return;
      }
      Pair<SortedMap<Interval, String>, Map<Interval, List<DataSegment>>> toBuildIntervalAndBaseSegments = checkSegments();
      SortedMap<Interval, String> sortedToBuildVersion = toBuildIntervalAndBaseSegments.lhs;
      Map<Interval, List<DataSegment>> baseSegments = toBuildIntervalAndBaseSegments.rhs;
      missInterval = sortedToBuildVersion.keySet();
      submitTasks(sortedToBuildVersion, baseSegments);
    }
  }
552291
async def cancel_remaining(self):
        ''''''
        self._closed = True
        task_list = list(self._pending)
        for task in task_list:
            task.cancel()
        for task in task_list:
            with suppress(CancelledError):
                await task
890846
protected boolean taskCanceled() {
        boolean cancel = canceled;
        if (!cancel) {
            for (K parent = getParent(); !cancel && parent != null; parent = parent.getParent())
                cancel = parent.canceled;
        }

        return cancel;
    }
1063218
private boolean isTaskRunning(TaskStatus taskStatus) {
    TaskStatus.State state = taskStatus.getRunState();
    return (state == State.RUNNING || state == State.UNASSIGNED || 
            taskStatus.inTaskCleanupPhase());
  }
1077692
function decreaseBufferPool () {
  if (bufferPool.length > 50 * 1024) {
    if (counter === 1 || notDecreased > counter * 2) {
      const minSliceLen = Math.floor(bufferPool.length / 10)
      const sliceLength = minSliceLen < bufferOffset
        ? bufferOffset
        : minSliceLen
      bufferOffset = 0
      bufferPool = bufferPool.slice(sliceLength, bufferPool.length)
    } else {
      notDecreased++
      counter--
    }
  } else {
    clearInterval(interval)
    counter = 0
    notDecreased = 0
    interval = null
  }
}
585780
public synchronized boolean removeTaskFromWaitQ(ParallelTask taskTobeRemoved) {
        boolean removed = false;
        for (ParallelTask task : waitQ) {
            if (task.getTaskId() == taskTobeRemoved.getTaskId()) {

                task.setState(ParallelTaskState.COMPLETED_WITH_ERROR);
                task.getTaskErrorMetas().add(
                        new TaskErrorMeta(TaskErrorType.USER_CANCELED, "NA"));
                logger.info(
                        "task {} removed from wait q. This task has been marked as USER CANCELED.",
                        task.getTaskId());
                removed = true;
            }
        }

        return removed;
    }