Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Resolve #195, ignore last_run_time when reconfiguring job.

  • Loading branch information...
commit ecab9b535bec928f29ae22c26e59fc0703388e78 1 parent 201e447
@dnephin dnephin authored
View
5 bin/tronview
@@ -141,7 +141,4 @@ def main():
if __name__ == '__main__':
- try:
- main()
- except Exception, e:
- print >>sys.stderr, e
+ main()
View
16 tests/core/job_test.py
@@ -5,7 +5,7 @@
from tests import mocks
from tests.assertions import assert_length, assert_call
from tests.mocks import MockNode
-from tests.testingutils import Turtle
+from tests.testingutils import Turtle, autospec_method
from tests import testingutils
from tron import node, event
from tron.core import job, jobrun
@@ -229,10 +229,11 @@ def test_disable(self):
assert_length(self.job.runs.cancel_pending.calls, 1)
def test_schedule_reconfigured(self):
- self.job_scheduler.schedule = Turtle()
+ autospec_method(self.job_scheduler.create_and_schedule_runs)
self.job_scheduler.schedule_reconfigured()
assert_length(self.job.runs.remove_pending.calls, 1)
- assert_length(self.job_scheduler.schedule.calls, 1)
+ self.job_scheduler.create_and_schedule_runs.assert_called_with(
+ ignore_last_run_time=True)
def test_run_job(self):
self.job_scheduler.schedule = Turtle()
@@ -333,11 +334,11 @@ def setup_job(self):
def test_get_runs_to_schedule_no_queue_with_pending(self):
self.scheduler.queue_overlapping = False
self.job.runs.has_pending = True
- job_runs = self.job_scheduler.get_runs_to_schedule()
+ job_runs = self.job_scheduler.get_runs_to_schedule(False)
assert_length(job_runs, 0)
def test_get_runs_to_schedule_queue_with_pending(self):
- job_runs = list(self.job_scheduler.get_runs_to_schedule())
+ job_runs = list(self.job_scheduler.get_runs_to_schedule(False))
self.job.runs.get_newest.assert_called_with(include_manual=False)
self.job.scheduler.next_run_time.assert_called_once_with(
@@ -347,7 +348,7 @@ def test_get_runs_to_schedule_queue_with_pending(self):
job_runs[0].attach.assert_any_call(True, self.job)
def test_get_runs_to_schedule_no_pending(self):
- job_runs = list(self.job_scheduler.get_runs_to_schedule())
+ job_runs = list(self.job_scheduler.get_runs_to_schedule(False))
self.job.runs.get_newest.assert_called_with(include_manual=False)
self.job.scheduler.next_run_time.assert_called_once_with(
@@ -359,7 +360,7 @@ def test_get_runs_to_schedule_no_pending(self):
def test_get_runs_to_schedule_no_last_run(self):
self.job.runs.get_newest.return_value = None
- job_runs = list(self.job_scheduler.get_runs_to_schedule())
+ job_runs = list(self.job_scheduler.get_runs_to_schedule(False))
self.job.scheduler.next_run_time.assert_called_once_with(None)
assert_length(job_runs, 1)
# This should return a JobRun which has the job attached as an observer
@@ -489,6 +490,5 @@ def get_queued(state):
self.job_scheduler.run_job.assert_not_called()
-
if __name__ == '__main__':
run()
View
16 tests/mcp_reconfigure_test.py
@@ -160,9 +160,9 @@ def test_job_unchanged(self):
assert 'MASTER.test_unchanged' in self.mcp.jobs
job_sched = self.mcp.jobs['MASTER.test_unchanged']
orig_job = job_sched.job
- run0 = job_sched.get_runs_to_schedule().next()
+ run0 = job_sched.get_runs_to_schedule(False).next()
run0.start()
- run1 = job_sched.get_runs_to_schedule().next()
+ run1 = job_sched.get_runs_to_schedule(False).next()
assert_equal(job_sched.job.name, "MASTER.test_unchanged")
action_map = job_sched.job.action_graph.action_map
@@ -185,7 +185,7 @@ def test_job_unchanged(self):
def test_job_unchanged_disabled(self):
job_sched = self.mcp.jobs['MASTER.test_unchanged']
orig_job = job_sched.job
- job_sched.get_runs_to_schedule().next()
+ job_sched.get_runs_to_schedule(False).next()
job_sched.disable()
self.reconfigure()
@@ -197,9 +197,9 @@ def test_job_unchanged_disabled(self):
def test_job_removed(self):
assert 'MASTER.test_remove' in self.mcp.jobs
job_sched = self.mcp.jobs['MASTER.test_remove']
- run0 = job_sched.get_runs_to_schedule().next()
+ run0 = job_sched.get_runs_to_schedule(False).next()
run0.start()
- run1 = job_sched.get_runs_to_schedule().next()
+ run1 = job_sched.get_runs_to_schedule(False).next()
assert_equal(job_sched.job.name, "MASTER.test_remove")
action_map = job_sched.job.action_graph.action_map
@@ -215,9 +215,9 @@ def test_job_removed(self):
def test_job_changed(self):
assert 'MASTER.test_change' in self.mcp.jobs
job_sched = self.mcp.jobs['MASTER.test_change']
- run0 = job_sched.get_runs_to_schedule().next()
+ run0 = job_sched.get_runs_to_schedule(False).next()
run0.start()
- job_sched.get_runs_to_schedule().next()
+ job_sched.get_runs_to_schedule(False).next()
assert_equal(len(job_sched.job.runs.runs), 2)
assert_equal(job_sched.job.name, "MASTER.test_change")
@@ -269,7 +269,7 @@ def test_job_new(self):
def test_daily_reschedule(self):
job_sched = self.mcp.jobs['MASTER.test_daily_change']
- job_sched.get_runs_to_schedule().next()
+ job_sched.get_runs_to_schedule(False).next()
assert_equal(len(job_sched.job.runs.runs), 1)
run = job_sched.job.runs.runs[0]
View
2  tron/commands/client.py
@@ -125,10 +125,12 @@ def object_events(self, item_url):
def request(self, url, data=None):
server = self.options.server
+ log.info("Request: %s, %s, %s", server, url, data)
status, content = request(server, url, data)
if not status == OK:
err_msg = "%s%s: %s"
raise RequestError(err_msg % (server, url, content))
+ log.info("Response: %s", content)
return content
View
13 tron/core/job.py
@@ -245,7 +245,10 @@ def enable(self):
return
self.job.enabled = True
- for job_run in self.get_runs_to_schedule(ignore_last_run_time=True):
+ self.create_and_schedule_runs(ignore_last_run_time=True)
+
+ def create_and_schedule_runs(self, ignore_last_run_time=False):
+ for job_run in self.get_runs_to_schedule(ignore_last_run_time):
self._set_callback(job_run)
def disable(self):
@@ -270,7 +273,7 @@ def schedule_reconfigured(self):
"""Remove the pending run and create new runs with the new JobScheduler.
"""
self.job.runs.remove_pending()
- self.schedule()
+ self.create_and_schedule_runs(ignore_last_run_time=True)
def schedule(self):
"""Schedule the next run for this job by setting a callback to fire
@@ -278,9 +281,7 @@ def schedule(self):
"""
if not self.job.enabled:
return
-
- for job_run in self.get_runs_to_schedule():
- self._set_callback(job_run)
+ self.create_and_schedule_runs()
def _set_callback(self, job_run):
"""Set a callback for JobRun to fire at the appropriate time."""
@@ -348,7 +349,7 @@ def handle_job_events(self, _observable, event):
self.schedule()
handler = handle_job_events
- def get_runs_to_schedule(self, ignore_last_run_time=False):
+ def get_runs_to_schedule(self, ignore_last_run_time):
"""Build and return the runs to schedule."""
if self.job.runs.has_pending:
log.info("%s has pending runs, can't schedule more." % self.job)
Please sign in to comment.
Something went wrong with that request. Please try again.