schedule a job to the type of workers spawned by self.start_workers.


        :param job: the job to schedule for running.
        :return:
547556
def schedule_job(self, job):
        
        l = _reraise_with_traceback(job.get_lambda_to_execute())

        future = self.workers.submit(l, update_progress_func=self.update_progress, cancel_job_func=self._check_for_cancel)

        # assign the futures to a dict, mapping them to a job
        self.job_future_mapping[future] = job
        self.future_job_mapping[job.job_id] = future

        # callback for when the future is now!
        future.add_done_callback(self.handle_finished_future)
        # add the job to our cancel notifications data structure, with False at first
        self.cancel_notifications[job.job_id] = False

        return future
791615
def load_job(self, job):
        
        if not isinstance(job, Job):
            self.log_exc(u"job is not an instance of Job", None, True, ExecuteJobInputError)
        self.job = job
1305204
def launch_background_job(self, job, on_error=None, on_success=None):
        
        if not self.main.mode_online:
            self.sortie_erreur_GUI(
                "Local mode activated. Can't run background task !")
            self.reset()
            return

        on_error = on_error or self.sortie_erreur_GUI
        on_success = on_success or self.sortie_standard_GUI

        def thread_end(r):
            on_success(r)
            self.update()

        def thread_error(r):
            on_error(r)
            self.reset()

        logging.info(
            f"Launching background task from interface {self.__class__.__name__} ...")
        th = threads.worker(job, thread_error, thread_end)
        self._add_thread(th)
1188146
def job_started(self, job, queue):
        
        job.hmset(start=str(datetime.utcnow()), status=STATUSES.RUNNING)
        job.tries.hincrby(1)
        self.log(self.job_started_message(job, queue))
        if hasattr(job, 'on_started'):
            job.on_started(queue)
107788
def ready(self, job):
        
        no_deps = len(job.depends_on) == 0
        all_complete = all(j.is_complete() for j in self.active_jobs
                if j.alias in job.depends_on)
        none_failed = not any(True for j in self.failed
                if j.alias in job.depends_on)
        queue_is_open = len(self.running) < self.MAX_CONCURRENT_JOBS
        return queue_is_open and (no_deps or (all_complete and none_failed))
808583
def schedule_next_job(self):
        
        next_job = self.storage_backend.get_next_scheduled_job()
        # TODO: don't loop over if workers are already all running

        if not next_job:
            logging.debug("No job to schedule right now.")
            return

        try:
            self.messaging_backend.send(self.worker_mailbox,
                                        Message(
                                            type=MessageType.START_JOB,
                                            message={'job': next_job}))
            self.storage_backend.mark_job_as_queued(next_job.job_id)
        except Full:
            logging.debug(
                "Worker queue full; skipping scheduling of job {} for now.".format(next_job.job_id)
            )
            return
1358588
function _activateJob(job) {
    var l = _sortedByPriorityJobs.length;

    // Add the job to the running jobs:
    _runningJobs[job.id] = job;
    job.status = 'running';

    // Add the job to the priorities:
    if (l) {
      job.weightTime = _sortedByPriorityJobs[l - 1].weightTime;
      job.currentTime = job.weightTime * (job.weight || 1);
    }

    // Initialize the job and dispatch:
    job.startTime = __dateNow();
    _dispatch('jobStarted', __clone(job));

    _sortedByPriorityJobs.push(job);
  }
984927
def format_jid_instance(jid, job):
    '''
    
    '''
    ret = format_job_instance(job)
    ret.update({'StartTime': jid_to_time(jid)})
    return ret
639661
def _runWorker(self, jobCommand, jobID, environment):
        
        startTime = time.time()  # Time job is started
        if self.debugWorker and "_toil_worker" in jobCommand:
            # Run the worker without forking
            jobName, jobStoreLocator, jobStoreID = jobCommand.split()[1:] # Parse command
            jobStore = Toil.resumeJobStore(jobStoreLocator)
            # TODO: The following does not yet properly populate self.runningJobs so it is not possible to kill
            # running jobs in forkless mode - see the "None" value in place of popen
            info = Info(time.time(), None, killIntended=False)
            try:
                self.runningJobs[jobID] = info
                try:
                    toil_worker.workerScript(jobStore, jobStore.config, jobName, jobStoreID, 
                                             redirectOutputToLogFile=not self.debugWorker) # Call the worker
                finally:
                    self.runningJobs.pop(jobID)
            finally:
                if not info.killIntended:
                    self.outputQueue.put((jobID, 0, time.time() - startTime))
        else:
            with self.popenLock:
                popen = subprocess.Popen(jobCommand,
                                         shell=True,
                                         env=dict(os.environ, **environment))
            info = Info(time.time(), popen, killIntended=False)
            try:
                self.runningJobs[jobID] = info
                try:
                    statusCode = popen.wait()
                    if statusCode != 0 and not info.killIntended:
                        log.error("Got exit code %i (indicating failure) "
                                  "from job %s.", statusCode, self.jobs[jobID])
                finally:
                    self.runningJobs.pop(jobID)
            finally:
                if not info.killIntended:
                    self.outputQueue.put((jobID, statusCode, time.time() - startTime))
1241102
def schedule_jobs(jobs)
      scheduler = Rufus::Scheduler.start_new

      jobs.each do |job|
        if job['cron']
          Mongolicious.logger.info("Scheduled new job for #{job['db'].split('/').last} with cron:  #{job['cron']}")
          scheduler.cron job['cron'] do
            backup(job)
          end
        else
          scheduler.every job['interval'] do
            Mongolicious.logger.info("Scheduled new job for #{job['db'].split('/').last} with interval: #{job['interval']}")
            backup(job)
          end
        end
      end

      scheduler.join
    end
1236666
def _start(self, worker=None):
        """"""
        if worker:
            self._queue_workers.append(worker)

        if self._queue_workers and self._running_threads < self._max_threads:
            #print('Queue: {0} Running: {1} Workers: {2} '
            #       'Threads: {3}'.format(len(self._queue_workers),
            #                                 self._running_threads,
            #                                 len(self._workers),
            #                                 len(self._threads)))
            self._running_threads += 1
            worker = self._queue_workers.popleft()
            thread = QThread()
            if isinstance(worker, PythonWorker):
                worker.moveToThread(thread)
                worker.sig_finished.connect(thread.quit)
                thread.started.connect(worker._start)
                thread.start()
            elif isinstance(worker, ProcessWorker):
                thread.quit()
                worker._start()
            self._threads.append(thread)
        else:
            self._timer.start()

        if self._workers:
            for w in self._workers:
                if w.is_finished():
                    self._bag_collector.append(w)
                    self._workers.remove(w)

        if self._threads:
            for t in self._threads:
                if t.isFinished():
                    self._threads.remove(t)
                    self._running_threads -= 1

        if len(self._threads) == 0 and len(self._workers) == 0:
            self._timer.stop()
            self._timer_worker_delete.start()
1236275
def start(self, *_):
        
        self.logger.info('Starting Scheduler...')
        db_manager.synch_db()
        self._load_managed_entries()

        try:
            self._load_freerun_entries()
        except LookupError as e:
            self.logger.warning('DB Lookup: {0}'.format(e))

        # Scheduler is initialized and running. GarbageCollector can be safely started
        self.gc.start()

        # Job/UOW Status Listeners can be safely started
        self.uow_listener.start()
        self.job_listener.start()

        self.logger.info('Startup Sequence Completed. Starting MX.')
        # Management Extension (MX) should be the last to start
        self.mx.start()
1194610
def batch_start(job, input_args):
    
    shared_files = ['ref.fa', 'ref.fa.amb', 'ref.fa.ann', 'ref.fa.bwt', 'ref.fa.pac', 'ref.fa.sa', 'ref.fa.fai']
    shared_ids = {}
    for fname in shared_files:
        url = input_args[fname]
        shared_ids[fname] = job.addChildJobFn(download_from_url, url, fname).rv()
    job.addFollowOnJobFn(spawn_batch_jobs, shared_ids, input_args)
318910
def job(self, name):
        
        for job in self.jobs():
            if job.data.name == name:
                return job
1013952
public boolean startJob(final Long jobId) {

		final ScheduledJob job = removeFromQueueInternal(jobId);

		if (job != null) {
			activeJobs.put(jobId, job);
			job.startJob();
			return true;
		} else {
			return false;
		}
	}
162115
def schedule_now(self, job):
        
        now = long(self._now() * 1e6)
        self.schedule(job, now)
952294
def reschedule_running_jobs
      @job_class.running.each do |job|
        begin
          Process.kill :QUIT, job.pid if job.pid.present?
        rescue Errno::ESRCH, Errno::EPERM
        ensure
          job.schedule
        end
      end
    end