From 668d271344883a9df30eaadf78d6e30fdf9ba963 Mon Sep 17 00:00:00 2001 From: James McGuinness Date: Mon, 12 Aug 2013 15:57:47 -0700 Subject: [PATCH] style cleanup in jobscheduler --- tron/core/job.py | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/tron/core/job.py b/tron/core/job.py index 4ec732698..619da3283 100644 --- a/tron/core/job.py +++ b/tron/core/job.py @@ -130,14 +130,12 @@ def __init__(self, job_runs, job_config, job_state, scheduler, actiongraph, def restore_state(self): """Restore the job state and schedule any JobRuns.""" - scheduled = [run for run in self.job_runs.get_scheduled()] + scheduled = list(self.job_runs.get_scheduled()) if scheduled: for job_run in scheduled: self._set_callback(job_run) else: - queued_run = self.job_runs.get_first_queued() - if queued_run: - eventloop.call_later(0, self.run_job, queued_run, run_queued=True) + self._run_first_queued() # Ensure we have at least 1 scheduled run self.schedule() @@ -235,6 +233,13 @@ def _queue_or_cancel_active(self, job_run): job_run.cancel() self.schedule() + def _run_first_queued(self): + # TODO: this should only start runs on the same node if this is an + # all_nodes job, but that is currently not possible + queued_run = self.job_runs.get_first_queued() + if queued_run: + eventloop.call_later(0, self.run_job, queued_run, run_queued=True) + def handle_job_events(self, _observable, event): """Handle notifications from observables. If a JobRun has completed look for queued JobRuns that may need to start now. @@ -242,11 +247,7 @@ def handle_job_events(self, _observable, event): if event != jobrun.JobRun.NOTIFY_DONE: return - # TODO: this should only start runs on the same node if this is an - # all_nodes job, but that is currently not possible - queued_run = self.job_runs.get_first_queued() - if queued_run: - eventloop.call_later(0, self.run_job, queued_run, run_queued=True) + self._run_first_queued() # Attempt to schedule a new run. This will only schedule a run if the # previous run was cancelled from a scheduled state, or if the job