Fixes on periodic tasks

This commit is contained in:
Marc Aymerich 2015-05-09 18:53:23 +00:00
parent 0d63a4ddad
commit c6c58d7d97
7 changed files with 16 additions and 7 deletions

View File

@ -314,8 +314,6 @@ https://code.djangoproject.com/ticket/24576
# inspecting django db connection for asserting db readines? or performing a query # inspecting django db connection for asserting db readines? or performing a query
# wake up django mailer on send_mail # wake up django mailer on send_mail
# all signals + accouns.register() services.register() on apps.py
from orchestra.contrib.tasks import task from orchestra.contrib.tasks import task
import time, sys import time, sys
@task(name='rata') @task(name='rata')
@ -355,3 +353,8 @@ make django admin taskstate uncollapse fucking traceback, ( if exists ?)
# backend.context and backned.instance provided when an action is called? like forms.cleaned_data: do it on manager.generation(backend.context = backend.get_context()) or in backend.__getattr__ ? also backend.head,tail,content switching on manager.generate()? # backend.context and backned.instance provided when an action is called? like forms.cleaned_data: do it on manager.generation(backend.context = backend.get_context()) or in backend.__getattr__ ? also backend.head,tail,content switching on manager.generate()?
resorce monitoring more efficient, less mem an better queries for calc current data resorce monitoring more efficient, less mem an better queries for calc current data
# best_price rating method
# error reporting on periodic tasks

View File

@ -94,6 +94,7 @@ class crontab_parser(object):
'Invalid beginning range: {0} < {1}.'.format(i, self.min_)) 'Invalid beginning range: {0} < {1}.'.format(i, self.min_))
return i return i
class Setting(object): class Setting(object):
def __init__(self, manage): def __init__(self, manage):
self.manage = manage self.manage = manage

View File

@ -7,5 +7,5 @@ MAILER_DEFERE_SECONDS = Setting('MAILER_DEFERE_SECONDS',
MAILER_MESSAGES_CLEANUP_DAYS = Setting('MAILER_MESSAGES_CLEANUP_DAYS', MAILER_MESSAGES_CLEANUP_DAYS = Setting('MAILER_MESSAGES_CLEANUP_DAYS',
10 7
) )

View File

@ -1,9 +1,11 @@
from datetime import timedelta
from django.utils import timezone from django.utils import timezone
from celery.task.schedules import crontab from celery.task.schedules import crontab
from orchestra.contrib.tasks import task, periodic_task from orchestra.contrib.tasks import task, periodic_task
from . import engine from . import engine, settings
@task @task
@ -17,4 +19,4 @@ def cleanup_messages():
delta = timedelta(days=settings.MAILER_MESSAGES_CLEANUP_DAYS) delta = timedelta(days=settings.MAILER_MESSAGES_CLEANUP_DAYS)
now = timezone.now() now = timezone.now()
epoch = (now-delta) epoch = (now-delta)
Message.objects.filter(state=Message.SENT, last_retry__lt=epoc).delete() return Message.objects.filter(state=Message.SENT, last_retry__lt=epoch).delete()

View File

@ -39,5 +39,5 @@ ORCHESTRATION_DISABLE_EXECUTION = Setting('ORCHESTRATION_DISABLE_EXECUTION',
ORCHESTRATION_BACKEND_CLEANUP_DAYS = Setting('ORCHESTRATION_BACKEND_CLEANUP_DAYS', ORCHESTRATION_BACKEND_CLEANUP_DAYS = Setting('ORCHESTRATION_BACKEND_CLEANUP_DAYS',
15 7
) )

View File

@ -5,6 +5,7 @@ from django.utils import timezone
from orchestra.contrib.tasks import periodic_task from orchestra.contrib.tasks import periodic_task
from . import settings
from .models import BackendLog from .models import BackendLog
@ -12,4 +13,4 @@ from .models import BackendLog
def backend_logs_cleanup(): def backend_logs_cleanup():
days = settings.ORCHESTRATION_BACKEND_CLEANUP_DAYS days = settings.ORCHESTRATION_BACKEND_CLEANUP_DAYS
epoch = timezone.now()-timedelta(days=days) epoch = timezone.now()-timedelta(days=days)
BackendLog.objects.filter(created_at__lt=epoch).delete() return BackendLog.objects.filter(created_at__lt=epoch).delete()

View File

@ -1,4 +1,5 @@
from django.apps import AppConfig from django.apps import AppConfig
from django.utils.module_loading import autodiscover_modules
from orchestra.core import administration from orchestra.core import administration
@ -12,3 +13,4 @@ class TasksConfig(AppConfig):
administration.register(TaskState, icon='Edit-check-sheet.png') administration.register(TaskState, icon='Edit-check-sheet.png')
administration.register(PeriodicTask, parent=TaskState, icon='Appointment.png') administration.register(PeriodicTask, parent=TaskState, icon='Appointment.png')
administration.register(WorkerState, parent=TaskState, dashboard=False) administration.register(WorkerState, parent=TaskState, dashboard=False)
autodiscover_modules('tasks')