Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JobQueue: Simpler API for adding jobs #484

Merged
merged 9 commits into from Dec 20, 2016

switch to run_x naming scheme

  • Loading branch information...
jh0ker committed Dec 14, 2016
commit cbf93e10461be399908e74e670d93e469db16d1e
Copy path View file
@@ -134,7 +134,7 @@ def _put(self, job, next_t=None, last_t=None):
# Wake up the loop if this job should be executed next
self._set_next_peek(next_t)

def one_time_job(self, callback, when, context=None, name=None):
def run_once(self, callback, when, context=None, name=None):
"""Creates a new ``Job`` that runs once and adds it to the queue.
Args:
@@ -164,7 +164,7 @@ def one_time_job(self, callback, when, context=None, name=None):
self._put(job, next_t=when)
return job

def repeating_job(self, callback, interval, first=None, context=None, name=None):
def run_repeating(self, callback, interval, first=None, context=None, name=None):
"""Creates a new ``Job`` that runs once and adds it to the queue.
Args:
@@ -197,7 +197,7 @@ def repeating_job(self, callback, interval, first=None, context=None, name=None)
self._put(job, next_t=first)
return job

def daily_job(self, callback, time, days=Days.EVERY_DAY, context=None, name=None):
def run_daily(self, callback, time, days=Days.EVERY_DAY, context=None, name=None):
"""Creates a new ``Job`` that runs once and adds it to the queue.
Args:
Copy path View file
@@ -229,31 +229,31 @@ def test_time_unit_dt_time_tomorrow(self):
self.jq.put(Job(self.job5, repeat=False), next_t=next_t)
self.assertAlmostEqual(self.jq.queue.get(False)[0], expected_time, delta=0.1)

def test_one_time_job(self):
def test_run_once(self):
delta = 2
expected_time = time.time() + delta

self.jq.one_time_job(self.job5, delta)
self.jq.run_once(self.job5, delta)
sleep(2.5)
self.assertAlmostEqual(self.job_time, expected_time, delta=0.1)

def test_repeating_job(self):
def test_run_repeating(self):
interval = 0.1
first = 1.5

self.jq.repeating_job(self.job1, interval, first=first)
self.jq.run_repeating(self.job1, interval, first=first)
sleep(2.505)
self.assertAlmostEqual(self.result, 10, delta=1)

def test_daily_job(self):
def test_run_daily(self):
delta = 1
current_time = datetime.datetime.now().time()
time_of_day = datetime.time(current_time.hour, current_time.minute,
current_time.second + delta, current_time.microsecond)

expected_time = time.time() + 60 * 60 * 24 + delta

self.jq.daily_job(self.job1, time_of_day)
self.jq.run_daily(self.job1, time_of_day)
sleep(2 * delta)
self.assertEqual(self.result, 1)
self.assertAlmostEqual(self.jq.queue.get(False)[0], expected_time, delta=0.1)
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.