Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed task_id() to use self.__class__.__name__ #10

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
Open
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
*.pyc
.idea/
.DS_Store
11 changes: 7 additions & 4 deletions periodically/backends.py
Original file line number Diff line number Diff line change
Expand Up @@ -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?
Expand Down
6 changes: 4 additions & 2 deletions periodically/management/commands/runtasks.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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])
Expand Down
2 changes: 1 addition & 1 deletion periodically/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.')
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down