Return all the currently-stalled jobs
19052
def stalled(self, offset=0, count=25):
        ''''''
        return self.client('jobs', 'stalled', self.name, offset, count)
616584
def all(cls):
        

        # Start with raw queues we know exist from the config
        queues = {x: 0 for x in Queue.get_queues_config()}

        stats = list(context.connections.mongodb_jobs.mrq_jobs.aggregate([
            {"$match": {"status": "queued"}},
            {"$group": {"_id": "$queue", "jobs": {"$sum": 1}}}
        ]))

        queues.update({x["_id"]: x["jobs"] for x in stats})

        return queues
334615
def find_jobs(self, job_ids):
        """"""
        matched_jobs = []
        if self.skip:
            return matched_jobs

        json_data = self.download_queue(job_ids)
        if not json_data:
            return matched_jobs

        jobs = json_data["jobs"]
        for job in jobs:
            if (
                job.get("id") in job_ids
                and job.get("status", "").lower() not in _NOT_FINISHED_STATUSES
            ):
                matched_jobs.append(job)

        return matched_jobs
619897
def wait(self):
        """"""
        logging.info("waiting for {} jobs to complete".format(len(self.submissions)))
        while not self.shutdown:
            time.sleep(1)
1306748
def system_find_jobs(input_params={}, always_retry=True, **kwargs):
    
    return DXHTTPRequest('/system/findJobs', input_params, always_retry=always_retry, **kwargs)
267312
def all_jobs(self):
        
        return list(set(self.complete + self.failed + self.queue + self.running))
866833
def done_tasks(self):
        """"""
        tasks = [task for task in self.all_tasks if task._state != NewTask._PENDING]
        return tasks
185876
def enqueue_jobs(self, jobs: Iterable[Job]):
        """"""
        for job in jobs:
            if job.should_start:
                job.status = JobStatus.QUEUED
                queue = self._get_queue(job.queue)
                queue.put(job.serialize())
            else:
                with self._lock:
                    job.status = JobStatus.WAITING
                    self._future_jobs.append(job.serialize())
                    self._future_jobs.sort(key=lambda j: Job.deserialize(j).at)
        self._something_happened.set()
969539
def current_jobs(self):
    

    jobs = []
    with synchronized(self.__queue):
      for worker in self.__threads:
        with synchronized(worker):
          if worker.current:
            jobs.append(worker.current)
    return jobs
120328
def resumable(self):
        ''''''
        # First, find the jids of all the jobs registered to this client.
        # Then, get the corresponding job objects
        jids = self.client.workers[self.client.worker_name]['jobs']
        jobs = self.client.jobs.get(*jids)

        # We'll filter out all the jobs that aren't in any of the queues
        # we're working on.
        queue_names = set([queue.name for queue in self.queues])
        return [job for job in jobs if job.queue_name in queue_names]
638664
def find_deadlocks(self):
        
        # Find jobs that can be submitted and and the jobs that are already in the queue.
        runnables = []
        for work in self:
            runnables.extend(work.fetch_alltasks_to_run())
        runnables.extend(list(self.iflat_tasks(status=self.S_SUB)))

        # Running jobs.
        running = list(self.iflat_tasks(status=self.S_RUN))

        # Find deadlocks.
        err_tasks = self.errored_tasks
        deadlocked = []
        if err_tasks:
            for task in self.iflat_tasks():
                if any(task.depends_on(err_task) for err_task in err_tasks):
                    deadlocked.append(task)

        return dict2namedtuple(deadlocked=deadlocked, runnables=runnables, running=running)
607572
def query_pending_jobs(auth, repo_name=None, return_raw=False):
    """"""
    url = '%s/pending?format=json' % HOST_ROOT
    LOG.debug('About to fetch %s' % url)
    req = requests.get(url, auth=auth, timeout=TCP_TIMEOUT)

    # If the revision doesn't exist on buildapi, that means there are
    # no builapi jobs for this revision
    if req.status_code not in [200]:
        return []

    raw = req.json()

    # If we don't want the data structure to be reduced
    if return_raw:
        return raw

    # If we only want pending jobs of a specific repo
    if repo_name and repo_name in list(raw['pending'].keys()):
        repo_list = [repo_name]
    else:
        repo_list = list(raw['pending'].keys())

    # Data structure to return
    data = {}
    for repo in repo_list:
        data[repo] = {}
        repo_jobs = raw['pending'][repo]
        for revision in repo_jobs.items():
            data[repo][revision[0]] = revision[1]

    return data
693258
def get_task(self, key):
        """"""
        res, pk = key
        jobs, lock = self._jobs
        with lock:
            return jobs[res].get(pk)
1057380
def enqueue_jobs(self, jobs: Iterable[Job]):
        """"""
        jobs_to_queue = list()
        for job in jobs:
            if job.should_start:
                job.status = JobStatus.QUEUED
            else:
                job.status = JobStatus.WAITING
            jobs_to_queue.append(job.serialize())

        if jobs_to_queue:
            self._run_script(
                self._enqueue_job,
                self._to_namespaced(NOTIFICATIONS_KEY),
                self._to_namespaced(RUNNING_JOBS_KEY.format(self._id)),
                self.namespace,
                self._to_namespaced(FUTURE_JOBS_KEY),
                *jobs_to_queue
            )
435787
def checkForDeadlocks(self):
        
        totalRunningJobs = len(self.batchSystem.getRunningBatchJobIDs())
        totalServicesIssued = self.serviceJobsIssued + self.preemptableServiceJobsIssued
        # If there are no updated jobs and at least some jobs running
        if totalServicesIssued >= totalRunningJobs and totalRunningJobs > 0:
            serviceJobs = [x for x in list(self.jobBatchSystemIDToIssuedJob.keys()) if isinstance(self.jobBatchSystemIDToIssuedJob[x], ServiceJobNode)]
            runningServiceJobs = set([x for x in serviceJobs if self.serviceManager.isRunning(self.jobBatchSystemIDToIssuedJob[x])])
            assert len(runningServiceJobs) <= totalRunningJobs

            # If all the running jobs are active services then we have a potential deadlock
            if len(runningServiceJobs) == totalRunningJobs:
                # We wait self.config.deadlockWait seconds before declaring the system deadlocked
                if self.potentialDeadlockedJobs != runningServiceJobs:
                    self.potentialDeadlockedJobs = runningServiceJobs
                    self.potentialDeadlockTime = time.time()
                elif time.time() - self.potentialDeadlockTime >= self.config.deadlockWait:
                    raise DeadlockException("The system is service deadlocked - all %d running jobs are active services" % totalRunningJobs)
            else:
                # We have observed non-service jobs running, so reset the potential deadlock
                self.potentialDeadlockedJobs = set()
                self.potentialDeadlockTime = 0
        else:
            # We have observed non-service jobs running, so reset the potential deadlock
            self.potentialDeadlockedJobs = set()
            self.potentialDeadlockTime = 0
899121
def get_jobs_by_status(status)
      r = []
      @jobs_by_id.values.each do |i|
        r << i if i.status == status.to_sym || status.to_sym == :all
      end
      return r
    end
789894
def list(self, allJobs=False):
        

        jobs = self.server.call('get', '/job')

        return [Job(job['id'], self.server) for job in jobs if allJobs or self._job_owned(job)]