MCPcopy Create free account
hub / github.com/coleifer/huey / loop

Method loop

huey/consumer.py:168–193  ·  view source on GitHub ↗
(self, now=None)

Source from the content-addressed store, hash-verified

166 self._next_periodic = time.monotonic()
167
168 def loop(self, now=None):
169 current = self._next_loop
170 self._next_loop += self.interval
171 if self._next_loop < time.monotonic():
172 self._logger.debug('scheduler skipping iteration to avoid race.')
173 self._next_loop = time.monotonic()
174 return
175
176 try:
177 task_list = self.huey.read_schedule(now)
178 except Exception:
179 self._logger.exception('Error reading schedule.')
180 else:
181 for task in task_list:
182 self._logger.debug('Enqueueing %s', task)
183 self.huey.enqueue(task)
184
185 if self.periodic and self._next_periodic <= time.monotonic():
186 # If the scheduler stalled (e.g. suspend/resume), skip past any
187 # missed checks rather than running them all back-to-back, which
188 # would enqueue duplicates for the current minute.
189 while self._next_periodic <= time.monotonic():
190 self._next_periodic += self.periodic_task_seconds
191 self.enqueue_periodic_tasks(now)
192
193 self.sleep_for_interval(current, self.interval)
194
195 def enqueue_periodic_tasks(self, now):
196 self._logger.debug('Checking periodic tasks')

Callers

nothing calls this directly

Calls 4

read_scheduleMethod · 0.45
enqueueMethod · 0.45
sleep_for_intervalMethod · 0.45

Tested by

no test coverage detected