Gets and removes a local or stolen task for the given worker.

@return a task, if available
350111
final ForkJoinTask<?> nextTaskFor(WorkQueue w) {
        for (ForkJoinTask<?> t;;) {
            WorkQueue q;
            if ((t = w.nextLocalTask()) != null)
                return t;
            if ((q = findNonEmptyStealQueue()) == null)
                return null;
            if ((t = q.pollAt(q.base)) != null)
                return t;
        }
    }
378134
private AuditUtilityTask getTask(String taskName) {
        AuditUtilityTask task = null;
        for (AuditUtilityTask availTask : tasks) {
            if (availTask.getTaskName().equals(taskName)) {
                task = availTask;
            }
        }
        return task;
    }
69785
String getWhereTaskletWasScheduledTo(final int taskletId) {
    for (final Map.Entry<String, VortexWorkerManager> entry : runningWorkers.entrySet()) {
      final String workerId = entry.getKey();
      final VortexWorkerManager vortexWorkerManager = entry.getValue();
      if (vortexWorkerManager.containsTasklet(taskletId)) {
        return workerId;
      }
    }
    return null;
  }
928218
def PopTask(self):
    
    try:
      _, task = heapq.heappop(self._heap)

    except IndexError:
      return None
    self._task_identifiers.remove(task.identifier)
    return task
487237
public TimerTask cancel(Serializable taskID) {
		
		if (logger.isDebugEnabled()) {
			logger.debug("Canceling task with timer id "+taskID);
		}
		
		TimerTask task = localRunningTasks.get(taskID);
		if (task != null) {
			// remove task data
			new TimerTaskCacheData(taskID, baseFqn, cluster).remove();

			final SetTimerAfterTxCommitRunnable setAction = task.getSetTimerTransactionalAction();
			if (setAction != null) {
				// we have a tx action scheduled to run when tx commits, to set the timer, lets simply cancel it
				setAction.cancel();
			}
			else {
				// do cancellation
				AfterTxCommitRunnable runnable = new CancelTimerAfterTxCommitRunnable(task,this);
				if (txManager != null) {
					try {
						Transaction tx = txManager.getTransaction();
						if (tx != null) {
							TransactionContext txContext = TransactionContextThreadLocal.getTransactionContext();
							if (txContext == null) {
								txContext = new TransactionContext();
								tx.registerSynchronization(new TransactionSynchronization(txContext));
							}
							txContext.put(taskID, runnable);					
						}
						else {
							runnable.run();
						}
					}
					catch (Throwable e) {
						throw new RuntimeException("Unable to register tx synchronization object",e);
					}
				}
				else {
					runnable.run();
				}			
			}		
		}
		else {
			// not found locally
			// if there is a tx context there may be a set timer action there
			if (txManager != null) {
				try {
					Transaction tx = txManager.getTransaction();
					if (tx != null) {
						TransactionContext txContext = TransactionContextThreadLocal.getTransactionContext();
						if (txContext != null) {
							final AfterTxCommitRunnable r = txContext.remove(taskID);
							if (r != null) {
								task = r.task;
								// remove from cluster
								new TimerTaskCacheData(taskID, baseFqn, cluster).remove();
							}							
						}											
					}
				}
				catch (Throwable e) {
					throw new RuntimeException("Failed to check tx context.",e);
				}
			}			
		}
		
		return task;
	}
1318728
public TedTask getTask(Long taskId) {
		if (taskId == null)
			return null;
		return tedDriverImpl.getTask(taskId);
	}
260155
def get_assigned_work_unit(self, worker_id, work_spec_name,
                               work_unit_key):
        '''
        '''
        with self.registry.lock(identifier=self.worker_id) as session:
            assigned_work_unit_key = session.get(
                WORK_UNITS_ + work_spec_name + '_locks', worker_id)
            if not assigned_work_unit_key == work_unit_key:
                # raise LostLease instead of EnvironmentError, so
                # users of TaskMaster can have a single type of
                # expected exception, rather than two
                raise LostLease(
                    'assigned_work_unit_key=%r != %r'
                    % (assigned_work_unit_key, work_unit_key))
            # could trap EnvironmentError and raise LostLease instead
            work_unit_data = session.get(WORK_UNITS_ + work_spec_name,
                                         work_unit_key)
            return WorkUnit(
                self.registry, work_spec_name,
                work_unit_key, work_unit_data,
                worker_id=worker_id,
                default_lifetime=self.default_lifetime,
            )
831505
private void cleanup(final String taskId)
  {
    if (!lifecycleLock.awaitStarted(1, TimeUnit.SECONDS)) {
      return;
    }
    final RemoteTaskRunnerWorkItem removed = completeTasks.remove(taskId);
    final Worker worker = removed.getWorker();
    if (removed == null || worker == null) {
      log.makeAlert("WTF?! Asked to cleanup nonexistent task")
         .addData("taskId", taskId)
         .emit();
    } else {
      final String workerId = worker.getHost();
      log.info("Cleaning up task[%s] on worker[%s]", taskId, workerId);
      final String statusPath = JOINER.join(indexerZkConfig.getStatusPath(), workerId, taskId);
      try {
        cf.delete().guaranteed().forPath(statusPath);
      }
      catch (KeeperException.NoNodeException e) {
        log.info("Tried to delete status path[%s] that didn't exist! Must've gone away already?", statusPath);
      }
      catch (Exception e) {
        throw new RuntimeException(e);
      }
    }
  }
658040
public synchronized Task obtainNewReduceTask(TaskTrackerStatus tts,
                                               int clusterSize,
                                               int numUniqueHosts
                                              ) throws IOException {
    if (status.getRunState() != JobStatus.RUNNING) {
      LOG.info("Cannot create task split for " + profile.getJobID());
      return null;
    }

    // Ensure we have sufficient map outputs ready to shuffle before
    // scheduling reduces
    if (!scheduleReduces()) {
      return null;
    }

    int  target = findNewReduceTask(tts, clusterSize, numUniqueHosts);
    if (target == -1) {
      return null;
    }

    Task result = reduces[target].getTaskToRun(tts.getTrackerName());
    if (result != null) {
      addRunningTaskToTIP(reduces[target], result.getTaskID(), tts, true);
    }

    return result;
  }
1356735
public Task obtainJobCleanupTask(
      String taskTrackerName, String hostName, boolean isMapSlot) {
    synchronized (lockObject) {
      if(!tasksInited || !jobSetupCleanupNeeded) {
        return null;
      }

      if (!canLaunchJobCleanupTaskUnprotected()) {
        return null;
      }

      List<TaskInProgress> cleanupTaskList = new ArrayList<TaskInProgress>();
      if (isMapSlot) {
        cleanupTaskList.add(cleanup[0]);
      } else {
        cleanupTaskList.add(cleanup[1]);
      }
      TaskInProgress tip =
        findTaskFromList(cleanupTaskList, hostName, false);
      if (tip == null) {
        return null;
      }

      // Now launch the cleanupTask
      Task result = tip.getTaskToRun(taskTrackerName);

      if (result != null) {
        addRunningTaskToTIPUnprotected(tip, result.getTaskID(), taskTrackerName, hostName,
            true);
        // Handle cleanup task
        setJobCleanupTaskState(result);
      }
      return result;
    }
  }
684533
function distributed_task(taskDef) {
	var worker = this[0], taskId = this[1], taskDef2;

	function replace_task_self(obj) {
		if (typeof(obj) == 'object') {
			for (var key in obj) {
				var value = obj[key];
				if (isDistributedTask(value) && (value.map === worker.TASK_SELF)) {
					value.map = taskId
				}
				else if (value instanceof Array) {
					value.forEach(replace_task_self)
				}
				else replace_task_self(value)
			}
		}
	}

	try {
		taskDef2 = def.decode(taskDef)
	}
	catch (e) {
		return worker.default_rejected({action: 'taskDef:decode', reason: e, task: taskId})
			.then(reject_me.bind("decode exception '" + e.message + "'for downloaded " + taskId));
	}

	// define taskDef.taskId
	Object.defineProperty(taskDef2, "taskId",
		{ "value": taskId, "enumerable": false, "writable": false, "configurable": false });

	// replace TASK_SELF in task.map only, with task.run.arguments.map
	replace_task_self(taskDef2);

	// call taskDef.distributed
	if ('distributed' in taskDef2) {
		try {
			taskDef2.distributed.call(worker, taskDef2)
		}
		catch (e) {
			return worker.default_rejected({action: 'taskDef:distributed', reason: e, task: taskId})
				.then(reject_me.bind("distributed method exception '" + e.message + "'in " + taskId));
		}
	}

	return taskDef2
}
800186
def delete_task(self, courseid, taskid):
        
        if not id_checker(courseid):
            raise InvalidNameException("Course with invalid name: " + courseid)
        if not id_checker(taskid):
            raise InvalidNameException("Task with invalid name: " + taskid)

        task_fs = self.get_task_fs(courseid, taskid)

        if task_fs.exists():
            task_fs.delete()
            get_course_logger(courseid).info("Task %s erased from the factory.", taskid)
1311236
def secret_from_transfer_task(
        transfer_task: Optional[TransferTask],
        secrethash: SecretHash,
) -> Optional[Secret]:
    """"""
    assert isinstance(transfer_task, InitiatorTask)

    transfer_state = transfer_task.manager_state.initiator_transfers[secrethash]

    if transfer_state is None:
        return None

    return transfer_state.transfer_description.secret
1096397
void lostTaskTracker(TaskTracker taskTracker) {
    String trackerName = taskTracker.getTrackerName();
    LOG.info("Lost tracker '" + trackerName + "'");

    // remove the tracker from the local structures
    synchronized (trackerToJobsToCleanup) {
      trackerToJobsToCleanup.remove(trackerName);
    }

    synchronized (trackerToTasksToCleanup) {
      trackerToTasksToCleanup.remove(trackerName);
    }

    Set<TaskAttemptIDWithTip> lostTasks = trackerToTaskMap.get(trackerName);
    trackerToTaskMap.remove(trackerName);

    if (lostTasks != null) {
      // List of jobs which had any of their tasks fail on this tracker
      Set<JobInProgress> jobsWithFailures = new HashSet<JobInProgress>();
      for (TaskAttemptIDWithTip oneTask : lostTasks) {
        TaskAttemptID taskId = oneTask.attemptId;
        TaskInProgress tip = oneTask.tip;
        JobInProgress job = (JobInProgress) tip.getJob();

        // Completed reduce tasks never need to be failed, because
        // their outputs go to dfs
        // And completed maps with zero reducers of the job
        // never need to be failed.
        if (!tip.isComplete() ||
            (tip.isMapTask() && !tip.isJobSetupTask() &&
             job.desiredReduces() != 0)) {
          // if the job is done, we don't want to change anything
          if (job.getStatus().getRunState() == JobStatus.RUNNING ||
              job.getStatus().getRunState() == JobStatus.PREP) {
            // the state will be KILLED_UNCLEAN, if the task(map or reduce)
            // was RUNNING on the tracker
            TaskStatus.State killState = (tip.isRunningTask(taskId) &&
              !tip.isJobSetupTask() && !tip.isJobCleanupTask()) ?
              TaskStatus.State.KILLED_UNCLEAN : TaskStatus.State.KILLED;
            job.failedTask(tip, taskId,
                          ("Lost task tracker: " + trackerName +
                            " at " + new Date()),
                           (tip.isMapTask() ?
                               TaskStatus.Phase.MAP :
                               TaskStatus.Phase.REDUCE),
                            killState,
                            trackerName);
            jobsWithFailures.add(job);
          }
        } else {
          // Completed 'reduce' task and completed 'maps' with zero
          // reducers of the job, not failed;
          // only removed from data-structures.
          markCompletedTaskAttempt(trackerName, taskId);
        }
      }

      // Penalize this tracker for each of the jobs which
      // had any tasks running on it when it was 'lost'
      // Also, remove any reserved slots on this tasktracker
      for (JobInProgress job : jobsWithFailures) {
        String reason = "Tracker went down";
        job.addTrackerTaskFailure(trackerName, taskTracker, reason);
      }

      // Cleanup
      taskTracker.cancelAllReservations();

      // Purge 'marked' tasks, needs to be done
      // here to prevent hanging references!
      removeMarkedTasks(trackerName);
    }
  }
736092
@Override public V get() {
    // check priorities - FJ task can only block on a task with higher priority!
    Thread cThr = Thread.currentThread();
    int priority = (cThr instanceof FJWThr) ? ((FJWThr)cThr)._priority : -1;
    // was hitting this (priority=1 but _dt.priority()=0 for DRemoteTask) - not clear who increased priority of FJWThr to 1...
    // assert _dt.priority() > priority || (_dt.priority() == priority && (_dt instanceof DRemoteTask || _dt instanceof MRTask2))
    assert _dt.priority() > priority || ((_dt instanceof DRemoteTask || _dt instanceof MRTask2))
      : "*** Attempting to block on task (" + _dt.getClass() + ") with equal or lower priority. Can lead to deadlock! " + _dt.priority() + " <=  " + priority;
    if( _done ) return result(); // Fast-path shortcut
    // Use FJP ManagedBlock for this blocking-wait - so the FJP can spawn
    // another thread if needed.
    try {
      try {
        ForkJoinPool.managedBlock(this);
      } catch (InterruptedException e) {
      }
    } catch(Throwable t){
      // catch and rethrow to preserve the stack trace!
      throw new RuntimeException(t);
    }
    if( _done ) return result(); // Fast-path shortcut
    assert isCancelled();
    return null;
  }
432101
public void remove(final Task task)
  {
    giant.lock();
    try {
      try {
        log.info("Removing task[%s] from activeTasks", task.getId());
        for (final TaskLockPosse taskLockPosse : findLockPossesForTask(task)) {
          unlock(task, taskLockPosse.getTaskLock().getInterval());
        }
      }
      finally {
        activeTasks.remove(task.getId());
      }
    }
    finally {
      giant.unlock();
    }
  }
214777
def _get_and_start_work(self):
        ""
        worker_id = nice_identifier()
        work_unit = self.task_master.get_work(worker_id, available_gb=self.available_gb())
        if work_unit is None:
            return None, None
        async_result = self.pool.apply_async(
            run_worker,
            (HeadlessWorker, self.task_master.registry.config,
             worker_id,
             work_unit.work_spec_name,
             work_unit.key),
            callback=self._finish_callback)
        return async_result, work_unit