Skip to content

Commit

Permalink
style cleanup in jobscheduler
Browse files Browse the repository at this point in the history
  • Loading branch information
James McGuinness committed Aug 12, 2013
1 parent befac57 commit 668d271
Showing 1 changed file with 10 additions and 9 deletions.
19 changes: 10 additions & 9 deletions tron/core/job.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down Expand Up @@ -235,18 +233,21 @@ 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.
"""
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
Expand Down

0 comments on commit 668d271

Please sign in to comment.