Get the number of pending work units for some work spec.

        These are work units that some worker is currently working on
        (hopefully; it could include work units assigned to workers that
        died and that have not yet expired).
772967
def num_pending(self, work_spec_name):
        '''

        '''
        return self.registry.len(WORK_UNITS_ + work_spec_name,
                                 priority_min=time.time())
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,
            )
1115835
def workers_status(self):
    """"""
    return [self._workers_status[identifier]
            for identifier in sorted(self._workers_status.keys())]
675856
@CheckForNull
    public WorkUnit getCurrentWorkUnit() {
        lock.readLock().lock();
        try {
            return workUnit;
        } finally {
            lock.readLock().unlock();
        }
    }
193493
public List<WorkUnitState> getTaskStatesAsWorkUnitStates() {
    ImmutableList.Builder<WorkUnitState> builder = ImmutableList.builder();
    for (TaskState taskState : this.taskStates.values()) {
      WorkUnitState workUnitState = new WorkUnitState(taskState.getWorkunit(), taskState.getJobState());
      workUnitState.setId(taskState.getId());
      workUnitState.addAll(taskState);
      builder.add(workUnitState);
    }

    return builder.build();
  }
1122121
def dump(self):
        '''

        '''
        with self.registry.lock(identifier=self.worker_id) as session:
            for work_spec_name in self.registry.pull(NICE_LEVELS).iterkeys():
                def scan(sfx):
                    v = self.registry.pull(WORK_UNITS_ + work_spec_name + sfx)
                    if v is None:
                        return []
                    return v.keys()
                for key in scan(''):
                    logger.debug('spec {0} unit {1} available or pending'
                                 .format(work_spec_name, key))
                for key in scan(_BLOCKED):
                    blocked_on = session.get(
                        WORK_UNITS_ + work_spec_name + _DEPENDS, key)
                    logger.debug('spec {0} unit {1} blocked on {2!r}'
                                 .format(work_spec_name, key, blocked_on))
                for key in scan(_FINISHED):
                    logger.debug('spec {0} unit {1} finished'
                                 .format(work_spec_name, key))
                for key in scan(_FAILED):
                    logger.debug('spec {0} unit {1} failed'
                                 .format(work_spec_name, key))
1288153
public function countWorkers()
    {
        $total = count($this->family);
        $busy = 0;
        $available = 0;
        foreach ($this->family as &$child) {
            switch ($child->status) {
                case ChildProcessContainer::STATUS_ALIVE:
                case ChildProcessContainer::STATUS_READY:
                    $available++;
                    break;
                case ChildProcessContainer::STATUS_BUSY:
                case ChildProcessContainer::STATUS_BUSY_BUT_SLEEPY:
                    $busy++;
                    break;
            }
        }
        return array($total, $available);
    }
663713
@Override
    public int getPendingCount() {
        if (log.isDebugEnabled()) log.debug("Pending Count = " + latch.getCount());
        return (int) latch.getCount();
    }
10301
def fail_work_unit(exception)
      keep_trying_to "mark work unit as failed" do
        data = base_params.merge({:status => 'failed', :output => {'output' => exception.message}.to_json})
        @node.central["/work/#{data[:id]}"].put(data)
        log "failed #{display_work_unit} in #{data[:time]} seconds\n#{exception.message}\n#{exception.backtrace}"
      end
    end
251007
def check_workers
    if @terminate
      @worker_threads.each { |t| 
        t.kill
      }
      @worker_threads = []

    elsif @timeout
      readd = []
      while @running_queue.size > 0 && work = @running_queue.pop
        # check expiration / killing expired threads must be atomic
        # and mutually exclusive with the process of marking a job completed above
        @thread_lock.synchronize{
          if work.expired?(@timeout)
            work.thread.kill
            @worker_threads.delete(work.thread)
            launch_worker

          elsif !work.completed?
            readd << work
          end
        }
      end
      readd.each { |work| @running_queue << work }
    end
  end
967234
public static function getStateOfWorkers()
    {
        $offset = 0;

        $stat = [
            'idle' => 0,
            'busy' => 0,
            'alive' => 0,
            'shutdown' => 0,
            'preinit' => 0,
            'init' => 0,
            'reloading' => 0,
        ];
        $readed = 0;
        while (($buf = Daemon::$shm_wstate->read($readed, 1024)) !== false) {
            $buflen = mb_orig_strlen($buf);
            $readed += $buflen;
            for ($i = 0; $i < $buflen; ++$i) {
                $code = ord($buf[$i]);
                if ($code >= 100) {
                    // reloaded (shutdown)
                    $code -= 100;
                    if ($code !== Daemon::WSTATE_SHUTDOWN) {
                        ++$stat['alive'];
                        if (Daemon::$process instanceof Thread\Master) {
                            Daemon::$process->reloadWorker($offset + $i + 1);
                            ++$stat['reloading'];
                            continue;
                        }
                    }
                }
                if ($code === Daemon::WSTATE_IDLE) {
                    // idle
                    ++$stat['alive'];
                    ++$stat['idle'];
                } elseif ($code === Daemon::WSTATE_BUSY) {
                    // busy
                    ++$stat['alive'];
                    ++$stat['busy'];
                } elseif ($code === Daemon::WSTATE_SHUTDOWN) {
                    // shutdown
                    ++$stat['shutdown'];
                } elseif ($code === Daemon::WSTATE_PREINIT) {
                    // pre-init
                    ++$stat['alive'];
                    ++$stat['preinit'];
                    ++$stat['idle'];
                } elseif ($code === Daemon::WSTATE_INIT) { // init
                    ++$stat['alive'];
                    ++$stat['init'];
                    ++$stat['idle'];
                }
            }
        }
        return $stat;
    }
983201
private void seekNext() {
    if (!needSeek) {
      return;
    }

    // First, iterate all
    if (this.currentIterator != null && this.currentIterator.hasNext()) {
      needSeek = false;
      return;
    }

    // Then, find the next available work unit
    nextWu = null;
    this.currentIterator = null;
    while (nextWu == null && workUnits.hasNext()) {
      nextWu = workUnits.next();
      if (nextWu instanceof MultiWorkUnit) {
        this.currentIterator = ((MultiWorkUnit) nextWu).getWorkUnits().iterator();
        if (!this.currentIterator.hasNext()) {
          nextWu = null;
        }
      }
    }

    needSeek = false;
  }
1229037
function () {
                    //Check if any input was added dynamically
                    if (job.input.length > 0) {
                        job.is_complete = false;
                        return false;
                    }

                    //Wait for workers or instances that are still working
                    return worker_count > 0 ? areWorkersComplete() : job.instances <= 0;
                }
134932
def GetStatusInformation(self):
    
    status = processing_status.TasksStatus()

    with self._lock:
      status.number_of_abandoned_tasks = len(self._tasks_abandoned)
      status.number_of_queued_tasks = len(self._tasks_queued)
      status.number_of_tasks_pending_merge = (
          len(self._tasks_pending_merge) + len(self._tasks_merging))
      status.number_of_tasks_processing = len(self._tasks_processing)
      status.total_number_of_tasks = self._total_number_of_tasks

    return status
605000
public List<WorkUnitState> getPreviousWorkUnitStates(String datasetUrn) {
    if (this.workUnitAndDatasetStateFunctional != null) {
      try {
        CombinedWorkUnitAndDatasetState state = this.workUnitAndDatasetStateFunctional.getCombinedWorkUnitAndDatasetState(datasetUrn);
        return state.getPreviousWorkUnitStates();
      } catch (Exception e) {
        throw new RuntimeException(e);
      }
    }
    return this.previousWorkUnitStates;
  }
375656
def _get_last_worker_died(self):
        """"""
        for service_id in list(self._running_services.keys()):
            # We copy the list to clean the orignal one
            processes = list(self._running_services[service_id].items())
            for process, worker_id in processes:
                if not process.is_alive():
                    self._run_hooks('dead_worker', service_id, worker_id,
                                    process.exitcode)
                    if process.exitcode < 0:
                        sig = _utils.signal_to_name(process.exitcode)
                        LOG.info('Child %(pid)d killed by signal %(sig)s',
                                 dict(pid=process.pid, sig=sig))
                    else:
                        LOG.info('Child %(pid)d exited with status %(code)d',
                                 dict(pid=process.pid, code=process.exitcode))
                    del self._running_services[service_id][process]
                    return service_id, worker_id
706405
def list_failed_work_units(self, work_spec_name, start=0, limit=None):
        
        return self.registry.filter(WORK_UNITS_ + work_spec_name + _FAILED,
                                    start=start, limit=limit)