Skip to content

Commit

Permalink
Small code cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
coleifer committed Jun 23, 2021
1 parent a0e03e2 commit bc39fcf
Showing 1 changed file with 5 additions and 6 deletions.
11 changes: 5 additions & 6 deletions huey/consumer.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,11 +138,12 @@ class Scheduler(BaseProcess):
If periodic tasks are enabled, the scheduler will wake up every 60 seconds
to enqueue any periodic tasks that should be run.
"""
periodic_task_seconds = 60
process_name = 'Scheduler'

def __init__(self, huey, interval, periodic):
super(Scheduler, self).__init__(huey)
self.interval = min(interval, 60)
self.interval = max(min(interval, 60), 1)

self.periodic = periodic
self._next_loop = time_clock()
Expand All @@ -164,11 +165,9 @@ def loop(self, now=None):
self._logger.debug('Enqueueing %s', task)
self.huey.enqueue(task)

if self.periodic:
current_p = self._next_periodic
if current_p <= time_clock():
self._next_periodic += 60
self.enqueue_periodic_tasks(now)
if self.periodic and self._next_periodic <= time_clock():
self._next_periodic += self.periodic_task_seconds
self.enqueue_periodic_tasks(now)

self.sleep_for_interval(current, self.interval)

Expand Down

0 comments on commit bc39fcf

Please sign in to comment.