Skip to content

Commit

Permalink
Merge branch 'cleanup_scheduler_and_job_running' of github.com:dnephi…
Browse files Browse the repository at this point in the history
…n/Tron into r0.4_bug_fixes_for_job_refactor
  • Loading branch information
Daniel Nephin committed May 11, 2012
2 parents 86dbe49 + b64ca4c commit 01cf90f
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 10 deletions.
4 changes: 2 additions & 2 deletions tests/core/job_test.py
Expand Up @@ -15,7 +15,7 @@ class JobContextTestCase(TestCase):

@setup
def setup_job(self):
self.last_success = datetime.datetime(2012, 3, 14)
self.last_success = Turtle(run_time=datetime.datetime(2012, 3, 14))
scheduler = Turtle()
run_collection = Turtle(last_success=self.last_success)
self.job = job.Job("jobname", scheduler, run_collection=run_collection)
Expand All @@ -26,7 +26,7 @@ def test_name(self):

def test__getitem__last_success(self):
item = self.context["last_success:day-1"]
expected = (self.last_success - datetime.timedelta(days=1)).day
expected = (self.last_success.run_time - datetime.timedelta(days=1)).day
assert_equal(item, str(expected))

item = self.context["last_success:shortdate"]
Expand Down
10 changes: 7 additions & 3 deletions tests/core/jobrun_test.py
Expand Up @@ -80,7 +80,7 @@ def test_state_data(self):
assert_equal(state_data['run_time'], self.run_time)

def test_set_action_runs(self):
del self.job_run.action_runs
self.job_run._action_runs = None
action_runs = [Turtle(), Turtle()]
run_collection = Turtle(action_runs_with_cleanup=action_runs)
self.job_run._set_action_runs(run_collection)
Expand All @@ -91,7 +91,7 @@ def test_set_action_runs(self):
assert self.job_run.action_runs_proxy

def test_set_action_runs_none(self):
del self.job_run.action_runs
self.job_run._action_runs = None
run_collection = Turtle(action_runs_with_cleanup=[])
self.job_run._set_action_runs(run_collection)
assert_length(self.job_run.watch.calls, 0)
Expand Down Expand Up @@ -246,6 +246,10 @@ def test_handler_finished_with_cleanup(self):
def test_state(self):
assert_equal(self.job_run.state, actionrun.ActionRun.STATE_SUCCEEDED)

def test_state_with_no_action_runs(self):
self.job_run._action_runs = None
assert_equal(self.job_run.state, actionrun.ActionRun.STATE_UNKNOWN)

def test_finalize(self):
timeutils.override_current_time(self.run_time)
self.job_run.action_runs.is_failed = False
Expand All @@ -270,7 +274,7 @@ def test_cleanup(self):
assert_call(self.job_run.output_path.delete, 0)
assert not self.job_run.node
assert not self.job_run.action_graph
assert not hasattr(self.job_run, '_action_runs')
assert not self.job_run.action_runs

def test__getattr__(self):
assert self.job_run.cancel
Expand Down
2 changes: 1 addition & 1 deletion tests/data/test_config.yaml
Expand Up @@ -51,7 +51,7 @@ jobs:
command: "%(ECHO)s %(actionname)s"
requires: [task0]
- name: task0
command: "sleep 3 && %(ECHO)s %(actionname)s"
command: "sleep 3 && %(ECHO)s %(actionname)s %(last_success:shortdate)s"


# IntervalScheduler dependent failure Actions
Expand Down
4 changes: 2 additions & 2 deletions tron/core/actionrun.py
Expand Up @@ -337,13 +337,13 @@ def command(self):

try:
self.rendered_command = self.render_command()
return self.rendered_command
except Exception:
log.error("Failed generating rendering command\n%s" %
traceback.format_exc())

# Return a command string that will always fail
return self.FAILED_RENDER
self.rendered_command = self.FAILED_RENDER
return self.rendered_command

@property
def is_valid_command(self):
Expand Down
2 changes: 2 additions & 0 deletions tron/core/job.py
Expand Up @@ -41,6 +41,8 @@ def __getitem__(self, item):

if date_name == 'last_success':
last_success = self.job.runs.last_success
last_success = last_success.run_time if last_success else None

time_value = timeutils.DateArithmetic.parse(date_spec, last_success)
if time_value:
return time_value
Expand Down
9 changes: 7 additions & 2 deletions tron/core/jobrun.py
Expand Up @@ -63,6 +63,7 @@ def __init__(self, job_name, run_num, run_time, node, output_path=None,
self.start_time = start_time
self.end_time = end_time
self.action_runs_proxy = None
self._action_runs = None
self.action_graph = action_graph
# TODO: expose this through the api
self.manual = manual
Expand Down Expand Up @@ -137,7 +138,7 @@ def _get_action_runs(self):

def _set_action_runs(self, run_collection):
"""Store action runs and register callbacks."""
if hasattr(self, '_action_runs'):
if self._action_runs is not None:
raise ValueError("ActionRunCollection already set on %s" % self)

self._action_runs = run_collection
Expand Down Expand Up @@ -254,14 +255,18 @@ def cleanup(self):
event.EventManager.get_instance().remove(self)
self.node = None
self.action_graph = None
del self.action_runs
self._action_runs = None
self.clear_observers()
self.output_path.delete()

@property
def state(self):
"""The overall state of this job run. Based on the state of its actions.
"""
if not self.action_runs:
log.info("%s has no state" % self)
return ActionRun.STATE_UNKNOWN

if self.action_runs.is_complete:
return ActionRun.STATE_SUCCEEDED
if self.action_runs.is_cancelled:
Expand Down

0 comments on commit 01cf90f

Please sign in to comment.