Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 9 additions & 5 deletions periodically/backends.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
from __future__ import print_function
from .models import ExecutionRecord
from django.utils import timezone
from .signals import task_complete
from .utils import get_scheduled_time
Expand Down Expand Up @@ -65,6 +64,7 @@ def run_tasks(self, tasks=None, fake=None):
self._run_tasks(tasks, fake, True)

def _run_tasks(self, tasks=None, fake=None, force=False):
from .models import ExecutionRecord
now = timezone.now()

# Verify that the provided tasks actually exist.
Expand All @@ -76,13 +76,13 @@ def _run_tasks(self, tasks=None, fake=None, force=False):

registered_task_ids = [task.task_id for task in tasks]

# Cancel the task if it's timed out.
# FIXME: This should only be called once per task (no matter how many times it's scheduled).
self.check_timeouts(now)

for task, schedule in self._schedules:
if not tasks or task.task_id in registered_task_ids:

# Cancel the task if it's timed out.
# FIXME: This should only be called once per task (no matter how many times it's scheduled).
self.check_timeout(task, now)

# If there are still tasks running, don't run the queue (as we
# could mess up the order).
if ExecutionRecord.objects.filter(end_time__isnull=True):
Expand All @@ -106,6 +106,7 @@ def _run_tasks(self, tasks=None, fake=None, force=False):
self.run_task(task, schedule, scheduled_time, now)

def check_timeout(self, task, now=None):
from .models import ExecutionRecord
from .settings import DEFAULT_TIMEOUT

if now is None:
Expand All @@ -131,6 +132,7 @@ def check_timeouts(self, now=None):
self.check_timeout(task, now)

def fake_task(self, task, schedule, scheduled_time=None, now=None):
from .models import ExecutionRecord
# TODO: Do we need both of these?
print('Faking periodic task "%s"' % task.task_id)
self.logger.info('Faking periodic task "%s"' % task.task_id)
Expand Down Expand Up @@ -159,6 +161,7 @@ def run_task(self, task, schedule, scheduled_time=None, now=None):

"""
# TODO: Do we need both of these?
from .models import ExecutionRecord
print('Running periodic task "%s"' % task.task_id)
self.logger.info('Running periodic task "%s"' % task.task_id)

Expand Down Expand Up @@ -212,6 +215,7 @@ def complete_task(self, task, success=True, extra=None):
<code>Logger.log()</code> as keyword args.

"""
from .models import ExecutionRecord
if extra is not None:
self.logger.log(**extra)

Expand Down