Skip to content

Commit

Permalink
Tests passing
Browse files Browse the repository at this point in the history
  • Loading branch information
ask committed Jun 27, 2014
1 parent 20340d7 commit c73bb64
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
13 changes: 9 additions & 4 deletions celery/beat.py
Original file line number Diff line number Diff line change
Expand Up @@ -209,21 +209,27 @@ def apply_entry(self, entry, producer=None):
else:
debug('%s sent. id->%s', entry.task, result.id)

def adjust(self, n, drift=-0.010):
if n and n > 0:
return n + drift
return n

def is_due(self, entry):
return entry.is_due()

def tick(self, drift=-0.010, event_t=event_t, min=min,
def tick(self, event_t=event_t, min=min,
heappop=heapq.heappop, heappush=heapq.heappush,
heapify=heapq.heapify):
"""Run a tick, that is one iteration of the scheduler.
Executes all due tasks.
"""
adjust = self.adjust
max_interval = self.max_interval
H = self._heap
if H is None:
H = self._heap = [event_t(e.is_due()[1] + drift or 0, 5, e)
H = self._heap = [event_t(adjust(e.is_due()[1]) or 0, 5, e)
for e in values(self.schedule)]
heapify(H)
event = H[0]
Expand All @@ -239,8 +245,7 @@ def tick(self, drift=-0.010, event_t=event_t, min=min,
else:
heappush(H, verify)
return min(verify[0], max_interval)
return min(next_time_to_run + drift if next_time_to_run
else max_interval, max_interval)
return min(adjust(next_time_to_run) or max_interval, max_interval)

def should_sync(self):
return (
Expand Down
4 changes: 2 additions & 2 deletions celery/tests/app/test_beat.py
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ def test_pending_tick(self):
scheduler = mScheduler(app=self.app)
scheduler.add(name='test_pending_tick',
schedule=always_pending)
self.assertEqual(scheduler.tick(), 1)
self.assertEqual(scheduler.tick(), 1 - 0.010)

def test_honors_max_interval(self):
scheduler = mScheduler(app=self.app)
Expand All @@ -303,7 +303,7 @@ def test_ticks(self):
{'schedule': mocked_schedule(False, j)})
for i, j in enumerate(nums))
scheduler.update_from_dict(s)
self.assertEqual(scheduler.tick(), min(nums))
self.assertEqual(scheduler.tick(), min(nums) - 0.010)

def test_schedule_no_remain(self):
scheduler = mScheduler(app=self.app)
Expand Down

0 comments on commit c73bb64

Please sign in to comment.