diff --git a/.gitignore b/.gitignore index 0205d62..a15a5be 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ *.pyc +.idea/ .DS_Store diff --git a/periodically/backends.py b/periodically/backends.py index 61e54e7..37cd746 100644 --- a/periodically/backends.py +++ b/periodically/backends.py @@ -76,15 +76,18 @@ def _run_tasks(self, tasks=None, fake=None, force=False): registered_task_ids = [task.task_id for task in tasks] + # check the timeouts for every task in the schedule 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) - # 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) + for task, schedule in self._schedules: + if not tasks or task.task_id in registered_task_ids: # If there are still tasks running, don't run the queue (as we # could mess up the order). + # Tasks scheduled with other backends can trigger this check. if ExecutionRecord.objects.filter(end_time__isnull=True): print('There are still tasks running; no new tasks will be run') # TODO: Should this behave differently if force == True? diff --git a/periodically/management/commands/runtasks.py b/periodically/management/commands/runtasks.py index c320f2b..7496856 100644 --- a/periodically/management/commands/runtasks.py +++ b/periodically/management/commands/runtasks.py @@ -1,4 +1,5 @@ from django.core.management.base import BaseCommand, CommandError +from django.db import transaction from ... import register as task_scheduler from optparse import make_option from ...utils import get_scheduler_backends_in_groups @@ -39,17 +40,18 @@ class Command(BaseCommand): ), ) + @transaction.atomic def handle(self, *args, **options): task_ids = args backend_groups = options.get('backend_groups', None) fake = options['fake'] force_execution = options['force_execution'] - + if backend_groups: backends = get_scheduler_backends_in_groups(backend_groups) else: backends = task_scheduler.backends - + for backend in backends: if task_ids: tasks = set([task for task in backend.tasks if task.task_id in task_ids]) diff --git a/periodically/tasks.py b/periodically/tasks.py index b90bab6..5dc8372 100644 --- a/periodically/tasks.py +++ b/periodically/tasks.py @@ -4,7 +4,7 @@ class PeriodicTask(object): @property def task_id(self): - return '%s.%s' % (self.__module__, self.__name__) + return '%s.%s' % (self.__module__, self.__class__.__name__) def run(self): raise RuntimeError('This method must be overridden by your class.') diff --git a/setup.py b/setup.py index 375a178..6094587 100644 --- a/setup.py +++ b/setup.py @@ -10,7 +10,7 @@ def read(fname): setup( name = "django-periodically", - version = "0.3.0", + version = "0.3.1", description='Periodic task management for your Django projects.', url = 'https://github.com/hzdg/django-periodically', long_description=README,