Updates the status of the job. When all the tasks are completed, run the join method in the
definition.
162636
private void updateStatus() {
    int completed = 0;
    List<TaskInfo> taskInfoList = mJobInfo.getTaskInfoList();
    for (TaskInfo info : taskInfoList) {
      switch (info.getStatus()) {
        case FAILED:
          mJobInfo.setStatus(Status.FAILED);
          if (mJobInfo.getErrorMessage().isEmpty()) {
            mJobInfo.setErrorMessage("Task execution failed: " + info.getErrorMessage());
          }
          return;
        case CANCELED:
          if (mJobInfo.getStatus() != Status.FAILED) {
            mJobInfo.setStatus(Status.CANCELED);
          }
          return;
        case RUNNING:
          if (mJobInfo.getStatus() != Status.FAILED && mJobInfo.getStatus() != Status.CANCELED) {
            mJobInfo.setStatus(Status.RUNNING);
          }
          break;
        case COMPLETED:
          completed++;
          break;
        case CREATED:
          // do nothing
          break;
        default:
          throw new IllegalArgumentException("Unsupported status " + info.getStatus());
      }
    }
    if (completed == taskInfoList.size()) {
      if (mJobInfo.getStatus() == Status.COMPLETED) {
        return;
      }

      // all the tasks completed, run join
      try {
        mJobInfo.setStatus(Status.COMPLETED);
        mJobInfo.setResult(join(taskInfoList));
      } catch (Exception e) {
        mJobInfo.setStatus(Status.FAILED);
        mJobInfo.setErrorMessage(e.getMessage());
      }
    }
  }
609562
@Override
	public void updateJobStatus(long instanceId, JobStatus jobStatus) {
		logger.entering(CLASSNAME, "updateJobStatus", new Object[] {instanceId, jobStatus});
		if (logger.isLoggable(Level.FINE)) {
			logger.fine("Updating Job Status to: " + jobStatus.getBatchStatus());
		}
		Connection conn = null;
		PreparedStatement statement = null;
		try {
			conn = getConnection();
			statement = conn.prepareStatement("UPDATE jobstatus SET obj = ? WHERE id = ?");
			statement.setBytes(1, serializeObject(jobStatus));
			statement.setLong(2, instanceId);
			statement.executeUpdate();
		} catch (SQLException e) {
			throw new PersistenceException(e);
		} catch (IOException e) {
			throw new PersistenceException(e);
		} finally {
			cleanupConnection(conn, null, statement);
		}
		logger.exiting(CLASSNAME, "updateJobStatus");
	}
1170051
def as_completed(jobs):
  '''  '''

  jobs = tuple(jobs)
  event = threading.Event()
  callback = lambda f, ev: event.set()
  [job.add_listener(Job.SUCCESS, callback, once=True) for job in jobs]
  [job.add_listener(Job.ERROR, callback, once=True) for job in jobs]

  while jobs:
    event.wait()
    event.clear()

    jobs, finished = split_list_by(jobs, lambda x: x.finished)
    for job in finished:
      yield job
1212517
@Override
  public void run() {
    try {
      if (tip.getTask().isMapTask()) {
        throw new RuntimeException("Only works for reducers!");
      }

      ReduceTask reduceTask = (ReduceTask) tip.getTask();

      LOG.info("MapperWaitThread started for reduce task " +
          reduceTask.getTaskID());
      int successfulMapCompletions = 0;
      int getFromEventId = 0;

      // Wait for the mappers in a loop
      while (successfulMapCompletions < reduceTask.getNumMaps()) {
        LOG.debug("Job: " + reduceTask.getJobID() + " ReduceTask: " +
            reduceTask.getTaskID() + " Got Successful Maps: " +
            successfulMapCompletions + "/" + reduceTask.getNumMaps());
        try {
          // This gets whether the mappers finished and also the location of the
          // output
          MapTaskCompletionEventsUpdate updates =
              umbilicalProtocol.getMapCompletionEvents(reduceTask.getJobID(), getFromEventId,
                  MAX_EVENTS_TO_FETCH, reduceTask.getTaskID());
          TaskCompletionEvent [] completionEvents =
              updates.getMapTaskCompletionEvents();

          if (updates.shouldReset()) {
            getFromEventId = 0;
            successfulMapCompletions = 0;
          }

          // Increment to get the next set of updates
          LOG.debug("Job: " + reduceTask.getJobID() + " ReduceTask: " +
              reduceTask.getTaskID() + " Got " +
              completionEvents.length + " map task " +
              " completion events");

          getFromEventId += completionEvents.length;

          // Tally up all the successful maps
          for(TaskCompletionEvent t : completionEvents) {
            if (t.getTaskStatus() == TaskCompletionEvent.Status.SUCCEEDED) {
              successfulMapCompletions++;
            }
          }

          // Update the progress of the threads so that they don't get killed
          // for inactivity
          umbilicalProtocol.statusUpdate(tip.getTask().getTaskID(), tip.getStatus());
          // If the thread were interrupted, then it means that we need to stop
          // as the task was killed
          if (Thread.interrupted()) {
            throw new InterruptedException("Generated in loop");
          }
          if (successfulMapCompletions % MAX_EVENTS_TO_FETCH == 0) {
            Thread.sleep(SLEEP_TIME);
          }

        } catch (IOException e) {
          LOG.error("Got an exception while getting map completion events", e);
        } catch (InterruptedException e) {
          LOG.debug("Got an interrupted exception while waiting for mappers  " +
              "for " + tip.getTask().getTaskID() + " job " +
              tip.getTask().getJobID());
          return;
        }
      }

      // All the mappers are done, so we can finish the reduce task
      LOG.info("Job: " + reduceTask.getJobID() + " ReduceTask: " +
          reduceTask.getTaskID() + " All maps finished, adding to task to " +
          "finish");
      taskRunner.addTipToFinish(tip, umbilicalProtocol);
    } finally {
      LOG.info("Exiting mapper wait thread " +
          "for " + tip.getTask().getTaskID() + " job " +
          tip.getTask().getJobID());
    }
  }
1055393
@Override
	public void run() {

		final long currentTime = System.currentTimeMillis();

		synchronized (this.collectedEvents) {

			final Iterator<JobID> it = this.collectedEvents.keySet().iterator();
			while (it.hasNext()) {

				final JobID jobID = it.next();
				final List<AbstractEvent> eventList = this.collectedEvents.get(jobID);
				if (eventList == null) {
					continue;
				}

				final Iterator<AbstractEvent> it2 = eventList.iterator();
				while (it2.hasNext()) {

					final AbstractEvent event = it2.next();
					// If the event is older than TIMERTASKINTERVAL, remove it
					if ((event.getTimestamp() + this.timerTaskInterval) < currentTime) {
						archiveEvent(jobID, event);
						it2.remove();
					}
				}

				if (eventList.isEmpty()) {
					it.remove();
				}
			}
		}

		synchronized (this.recentJobs) {

			final Iterator<Map.Entry<JobID, RecentJobEvent>> it = this.recentJobs.entrySet().iterator();
			while (it.hasNext()) {

				final Map.Entry<JobID, RecentJobEvent> entry = it.next();
				final JobStatus jobStatus = entry.getValue().getJobStatus();

				// Only remove jobs from the list which have stopped running
				if (jobStatus != JobStatus.FINISHED && jobStatus != JobStatus.CANCELED
					&& jobStatus != JobStatus.FAILED) {
					continue;
				}

				// Check time stamp of last job status update
				if ((entry.getValue().getTimestamp() + this.timerTaskInterval) < currentTime) {
					archiveJobevent(entry.getKey(), entry.getValue());
					it.remove();
					synchronized (this.recentManagementGraphs) {
						archiveManagementGraph(entry.getKey(), this.recentManagementGraphs.get(entry.getKey()));
						this.recentManagementGraphs.remove(entry.getValue());
					}
					synchronized (this.recentNetworkTopologies) {
						archiveNetworkTopology(entry.getKey(), this.recentNetworkTopologies.get(entry.getKey()));
						this.recentNetworkTopologies.remove(entry.getValue());
					}
				}
			}
		}
	}
425359
public synchronized void updateTaskStatus(TaskInProgress tip,
                                            TaskStatus status) {

    double oldProgress = tip.getProgress();   // save old progress
    boolean wasRunning = tip.isRunning();
    boolean wasComplete = tip.isComplete();
    boolean wasPending = tip.isOnlyCommitPending();
    TaskAttemptID taskid = status.getTaskID();
    boolean wasAttemptRunning = tip.isAttemptRunning(taskid);

    // If the TIP is already completed and the task reports as SUCCEEDED then
    // mark the task as KILLED.
    // In case of task with no promotion the task tracker will mark the task
    // as SUCCEEDED.
    // User has requested to kill the task, but TT reported SUCCEEDED,
    // mark the task KILLED.
    if ((wasComplete || tip.wasKilled(taskid)) &&
        (status.getRunState() == TaskStatus.State.SUCCEEDED)) {
      status.setRunState(TaskStatus.State.KILLED);
    }

    // When a task has just reported its state as FAILED_UNCLEAN/KILLED_UNCLEAN,
    // if the job is complete or cleanup task is switched off,
    // make the task's state FAILED/KILLED without launching cleanup attempt.
    // Note that if task is already a cleanup attempt,
    // we don't change the state to make sure the task gets a killTaskAction
    if ((this.isComplete() || jobFailed || jobKilled || !taskCleanupNeeded) &&
        !tip.isCleanupAttempt(taskid)) {
      if (status.getRunState() == TaskStatus.State.FAILED_UNCLEAN) {
        status.setRunState(TaskStatus.State.FAILED);
      } else if (status.getRunState() == TaskStatus.State.KILLED_UNCLEAN) {
        status.setRunState(TaskStatus.State.KILLED);
      }
    }

    boolean change = tip.updateStatus(status);
    if (change) {
      TaskStatus.State state = status.getRunState();
      // get the TaskTrackerStatus where the task ran
      TaskTracker taskTracker =
        this.jobtracker.getTaskTracker(tip.machineWhereTaskRan(taskid));
      TaskTrackerStatus ttStatus =
        (taskTracker == null) ? null : taskTracker.getStatus();
      String httpTaskLogLocation = null;

      if (null != ttStatus){
        String host;
        if (NetUtils.getStaticResolution(ttStatus.getHost()) != null) {
          host = NetUtils.getStaticResolution(ttStatus.getHost());
        } else {
          host = ttStatus.getHost();
        }
        httpTaskLogLocation = "http://" + host + ":" + ttStatus.getHttpPort();
           //+ "/tasklog?plaintext=true&taskid=" + status.getTaskID();
      }

      TaskCompletionEvent taskEvent = null;
      if (state == TaskStatus.State.SUCCEEDED) {
        TaskCompletionEvent.Status taskCompletionStatus = TaskCompletionEvent.Status.SUCCEEDED;
        // Ensure that this is a map task.
        boolean isMapTask = status.getIsMap() && !tip.isJobCleanupTask() && !tip.isJobSetupTask();
        if (enableNoFetchEmptyMapOutputs && isMapTask) {
          long outBytes = status.getCounters().getCounter(Task.Counter.MAP_OUTPUT_BYTES);
          if (outBytes == 0) {
            taskCompletionStatus = TaskCompletionEvent.Status.SUCCEEDED_NO_OUTPUT;
          }
        }
        taskEvent = new TaskCompletionEvent(
                                            taskCompletionEventTracker,
                                            taskid,
                                            tip.idWithinJob(),
                                            isMapTask,
                                            taskCompletionStatus,
                                            httpTaskLogLocation
                                           );
        taskEvent.setTaskRunTime((int)(status.getFinishTime()
                                       - status.getStartTime()));
        tip.setSuccessEventNumber(taskCompletionEventTracker);
      } else if (state == TaskStatus.State.COMMIT_PENDING) {
        // If it is the first attempt reporting COMMIT_PENDING
        // ask the task to commit.
        if (!wasComplete && !wasPending) {
          tip.doCommit(taskid);
        }
        return;
      } else if (state == TaskStatus.State.FAILED_UNCLEAN ||
                 state == TaskStatus.State.KILLED_UNCLEAN) {
        tip.incompleteSubTask(taskid, this.status);
        // add this task, to be rescheduled as cleanup attempt
        if (tip.isMapTask()) {
          mapCleanupTasks.add(taskid);
        } else {
          reduceCleanupTasks.add(taskid);
        }
        // Remove the task entry from jobtracker
        jobtracker.removeTaskEntry(taskid);
      }
      //For a failed task update the JT datastructures.
      else if (state == TaskStatus.State.FAILED ||
               state == TaskStatus.State.KILLED) {
        // Get the event number for the (possibly) previously successful
        // task. If there exists one, then set that status to OBSOLETE
        int eventNumber;
        if ((eventNumber = tip.getSuccessEventNumber()) != -1) {
          TaskCompletionEvent t =
            this.taskCompletionEvents.get(eventNumber);
          if (t.getTaskAttemptId().equals(taskid))
            t.setTaskStatus(TaskCompletionEvent.Status.OBSOLETE);
        }

        // Tell the job to fail the relevant task
        failedTask(tip, taskid, status, taskTracker,
                   wasRunning, wasComplete, wasAttemptRunning);

        // Did the task failure lead to tip failure?
        TaskCompletionEvent.Status taskCompletionStatus =
          (state == TaskStatus.State.FAILED ) ?
              TaskCompletionEvent.Status.FAILED :
              TaskCompletionEvent.Status.KILLED;
        if (tip.isFailed()) {
          taskCompletionStatus = TaskCompletionEvent.Status.TIPFAILED;
        }
        taskEvent = new TaskCompletionEvent(taskCompletionEventTracker,
                                            taskid,
                                            tip.idWithinJob(),
                                            status.getIsMap() &&
                                            !tip.isJobCleanupTask() &&
                                            !tip.isJobSetupTask(),
                                            taskCompletionStatus,
                                            httpTaskLogLocation
                                           );
      }

      // Add the 'complete' task i.e. successful/failed
      // It _is_ safe to add the TaskCompletionEvent.Status.SUCCEEDED
      // *before* calling TIP.completedTask since:
      // a. One and only one task of a TIP is declared as a SUCCESS, the
      //    other (speculative tasks) are marked KILLED by the TaskCommitThread
      // b. TIP.completedTask *does not* throw _any_ exception at all.
      if (taskEvent != null) {
        this.taskCompletionEvents.add(taskEvent);
        taskCompletionEventTracker++;
        JobTrackerStatistics.TaskTrackerStat ttStat = jobtracker.
           getStatistics().getTaskTrackerStat(tip.machineWhereTaskRan(taskid));
        if(ttStat != null) { // ttStat can be null in case of lost tracker
          ttStat.incrTotalTasks();
        }
        if (state == TaskStatus.State.SUCCEEDED) {
          completedTask(tip, status);
          if(ttStat != null) {
            ttStat.incrSucceededTasks();
          }
        }
        countersLog.info(status.getTaskID() + " completion counters "
            + status.getCounters().makeJsonString());
      }
    }

    //
    // Update JobInProgress status
    //
    if(LOG.isDebugEnabled()) {
      LOG.debug("Taking progress for " + tip.getTIPId() + " from " +
                 oldProgress + " to " + tip.getProgress());
    }

    if (!tip.isJobCleanupTask() && !tip.isJobSetupTask()) {
      double progressDelta = tip.getProgress() - oldProgress;
      if (tip.isMapTask()) {
          this.status.setMapProgress((float) (this.status.mapProgress() +
                                              progressDelta / maps.length));
      } else {
        this.status.setReduceProgress((float) (this.status.reduceProgress() +
                                           (progressDelta / reduces.length)));
      }
    }
  }
33258
private void taskComplete(
      HttpRemoteTaskRunnerWorkItem taskRunnerWorkItem,
      WorkerHolder workerHolder,
      TaskStatus taskStatus
  )
  {
    Preconditions.checkState(!Thread.holdsLock(statusLock), "Current thread must not hold statusLock.");
    Preconditions.checkNotNull(taskRunnerWorkItem, "taskRunnerWorkItem");
    Preconditions.checkNotNull(taskStatus, "taskStatus");
    if (workerHolder != null) {
      log.info(
          "Worker[%s] completed task[%s] with status[%s]",
          workerHolder.getWorker().getHost(),
          taskStatus.getId(),
          taskStatus.getStatusCode()
      );
      // Worker is done with this task
      workerHolder.setLastCompletedTaskTime(DateTimes.nowUtc());
    }

    // Notify interested parties
    taskRunnerWorkItem.setResult(taskStatus);
    TaskRunnerUtils.notifyStatusChanged(listeners, taskStatus.getId(), taskStatus);

    // Update success/failure counters, Blacklist node if there are too many failures.
    if (workerHolder != null) {
      blacklistWorkerIfNeeded(taskStatus, workerHolder);
    }

    synchronized (statusLock) {
      statusLock.notifyAll();
    }
  }
841174
def finish(self, result, array_id = None):
    """"""
    # check if there is any array job still running
    new_status = 'success' if result == 0 else 'failure'
    new_result = result
    finished = True
    if array_id is not None:
      for array_job in self.array:
        if array_job.id == array_id:
          array_job.status = new_status
          array_job.result = result
          array_job.finish_time = datetime.now()
        if array_job.status not in ('success', 'failure'):
          finished = False
        elif new_result == 0:
          new_result = array_job.result

    if finished:
      # There was no array job, or all array jobs finished
      self.status = 'success' if new_result == 0 else 'failure'
      self.result = new_result
      self.finish_time = datetime.now()

      # update all waiting jobs
      for job in self.get_jobs_waiting_for_us():
        if job.status == 'waiting':
          job.queue()
1328573
private void jobComplete() {
    final JobTrackerInstrumentation metrics = jobtracker.getInstrumentation();
    //
    // All tasks are complete, then the job is done!
    //
    if (this.status.getRunState() == JobStatus.RUNNING ||
        this.status.getRunState() == JobStatus.PREP) {
      changeStateTo(JobStatus.SUCCEEDED);
      this.status.setCleanupProgress(1.0f);
      if (maps.length == 0) {
        this.status.setMapProgress(1.0f);
      }
      if (reduces.length == 0) {
        this.status.setReduceProgress(1.0f);
      }
      this.finishTime = JobTracker.getClock().getTime();
      LOG.info("Job " + this.status.getJobID() +
               " has completed successfully.");

      // Log the job summary (this should be done prior to logging to
      // job-history to ensure job-counters are in-sync
      JobSummary.logJobSummary(this, jobtracker.getClusterStatus(false));

      Counters counters = getCounters();
      // Log job-history
      JobHistory.JobInfo.logFinished(this.status.getJobID(), finishTime,
                                     this.finishedMapTasks,
                                     this.finishedReduceTasks, failedMapTasks,
                                     failedReduceTasks, killedMapTasks,
                                     killedReduceTasks, getMapCounters(),
                                     getReduceCounters(), counters);
      // Note that finalize will close the job history handles which garbage collect
      // might try to finalize
      garbageCollect();

      metrics.completeJob(this.conf, this.status.getJobID());
    }
  }
421959
def run(self):
        '''
        '''
        if self.verbose:
            pbar = tqdm(total=100)
        while True:
            task_remain = self._task_queue.qsize()
            task_finished = int((float(self.total_task - task_remain) /
                                 float(self.total_task)) * 100)
            if task_finished % 20 == 0 and task_finished != self.current_state:
                self.current_state = task_finished
                logger.info('{0}% done'.format(task_finished))
                if self.verbose and task_finished > 0:
                    pbar.update(20)
            if task_remain == 0:
                break
        logger.debug('All task data cleared')
44349
def _update_statuses(self, sub_job_num=None):
        
        # initialize status dictionary
        status_dict = dict()

        for val in CONDOR_JOB_STATUSES.values():
            status_dict[val] = 0

        for node in self.node_set:
            job = node.job
            try:
                job_status = job.status
                status_dict[job_status] += 1
            except (KeyError, HTCondorError):
                status_dict['Unexpanded'] += 1

        return status_dict
1244420
function taskComplete() {
  winston.info(_pkgname + "task done #"+this.id + ' [' + this.data.id + ']');
  // now instantiate the next set of tasks
  //issueJobsNextLevel(this.data.jobname, this, this.data.flow);
  if(this.data._done) {
    this.data._done(this);
  }
}
1274533
public void updateStatus(JobStatus newStatus) {
    JobMonitor monitor = getJobMonitor(newStatus);
    monitor.updateStatus(newStatus);
  }
601748
public void run(final StatusUpdate onStatus,
                    final Command onCompletion) {
        //Ensure active analysis is cancelled
        cancelExistingAnalysis();

        //If there are no checks to run simply return
        if (rechecks.isEmpty()) {
            if (onCompletion != null) {
                onCompletion.execute();
                return;
            }
        }

        checkRunner.run(rechecks,
                        onStatus,
                        onCompletion);
        rechecks.clear();
    }
547676
def notify_batches_finished(self, statuses):
        
        with self._wait_condition:
            self._statuses = statuses
            self._wait_condition.notify()
1014648
private void internalUpdateJobStateAndResult(final JobInstance job) {
        transactionTemplate.execute(new TransactionCallbackWithoutResult() {
            protected void doInTransactionWithoutResult(TransactionStatus status) {
                jobInstanceDao.updateStateAndResult(job);
                if (job.isCompleted()) {
                    buildPropertiesService.saveCruiseProperties(job);
                }
            }
        });
    }
1178256
protected void update() {
    //Making more granual locking so that clusterStatus can be fetched from Jobtracker.
    ClusterStatus clusterStatus = taskTrackerManager.getClusterStatus();
    // Recompute locality delay from JobTracker heartbeat interval if enabled.
    // This will also lock the JT, so do it outside of a fair scheduler lock.
    if (autoComputeLocalityDelay) {
      JobTracker jobTracker = (JobTracker) taskTrackerManager;
      localityDelayNodeLocal = Math.min(MAX_AUTOCOMPUTED_LOCALITY_DELAY,
           (long) (1.5 * jobTracker.getNextHeartbeatInterval()));
      localityDelayRackLocal = localityDelayNodeLocal;
    }
    // Got clusterStatus hence acquiring scheduler lock now
    // Remove non-running jobs
    synchronized(this){

      // Reload allocations file if it hasn't been loaded in a while
      if (poolMgr.reloadAllocsIfNecessary()) {
        // Check if the cluster have enough slots for reserving
        poolMgr.checkMinimumSlotsAvailable(clusterStatus, TaskType.MAP);
        poolMgr.checkMinimumSlotsAvailable(clusterStatus, TaskType.REDUCE);
      }

      List<JobInProgress> toRemove = new ArrayList<JobInProgress>();
      for (JobInProgress job: infos.keySet()) {
        int runState = job.getStatus().getRunState();
        if (runState == JobStatus.SUCCEEDED || runState == JobStatus.FAILED
          || runState == JobStatus.KILLED) {
            toRemove.add(job);
        }
      }
      for (JobInProgress job: toRemove) {
        infos.remove(job);
        poolMgr.removeJob(job);
      }
      // Update running jobs with deficits since last update, and compute new
      // slot allocations, weight, shares and task counts
      long now = clock.getTime();
      long timeDelta = now - lastUpdateTime;
      updateDeficits(timeDelta);
      updateRunnability();
      updateTaskCounts();
      updateWeights();
      updateMinAndMaxSlots();
      updateFairShares(clusterStatus);
      if (preemptionEnabled) {
        updatePreemptionVariables();
      }
      sortJobs();
      updatePoolMetrics();
      dumpStatus(now);
      lastUpdateTime = now;
    }
  }