django-orchestra-test/orchestra/contrib/mailer/tasks.py

21 lines
526 B
Python
Raw Normal View History

2015-05-05 19:42:55 +00:00
from django.utils import timezone
from celery.task.schedules import crontab
2015-05-04 19:52:53 +00:00
2015-05-05 19:42:55 +00:00
from orchestra.contrib.tasks import task, periodic_task
2015-05-04 19:52:53 +00:00
2015-05-05 19:42:55 +00:00
from . import engine
@task
def send_message(message):
engine.send_message(message)
@periodic_task(run_every=crontab(hour=7, minute=30))
2015-05-04 19:52:53 +00:00
def cleanup_messages():
2015-05-05 19:42:55 +00:00
from .models import Message
delta = timedelta(days=settings.MAILER_MESSAGES_CLEANUP_DAYS)
now = timezone.now()
epoch = (now-delta)
Message.objects.filter(state=Message.SENT, last_retry__lt=epoc).delete()