annotate gpp/core/tasks.py @ 516:beda97542da8

For #194, add a celery beat task for Django & forum cleanup.
author Brian Neal <bgneal@gmail.com>
date Thu, 15 Dec 2011 00:59:32 +0000
parents 9e7ae8462f3f
children 666147a2cc08
rev   line source
bgneal@513 1 """
bgneal@513 2 Celery tasks for the core application.
bgneal@513 3
bgneal@513 4 """
bgneal@513 5 from celery.task import task
bgneal@513 6 import django.core.mail
bgneal@516 7 from django.core.management.commands.cleanup import Command as CleanupCommand
bgneal@516 8 from forums.management.commands.forum_cleanup import Command as ForumCleanup
bgneal@513 9
bgneal@513 10
bgneal@513 11 @task
bgneal@513 12 def add(x, y):
bgneal@516 13 """
bgneal@516 14 It is useful to have a test task laying around. This is it.
bgneal@516 15
bgneal@516 16 """
bgneal@513 17 return x + y
bgneal@513 18
bgneal@516 19
bgneal@513 20 @task
bgneal@513 21 def send_mail(subject, message, from_email, recipient_list, **kwargs):
bgneal@516 22 """
bgneal@516 23 A task to send mail via Django.
bgneal@516 24
bgneal@516 25 """
bgneal@513 26 django.core.mail.send_mail(subject, message, from_email, recipient_list,
bgneal@513 27 **kwargs)
bgneal@516 28
bgneal@516 29
bgneal@516 30 @task
bgneal@516 31 def cleanup():
bgneal@516 32 """
bgneal@516 33 A task to perform site-wide cleanup actions.
bgneal@516 34
bgneal@516 35 """
bgneal@516 36 # Execute Django's cleanup command (deletes old sessions).
bgneal@516 37
bgneal@516 38 command = CleanupCommand()
bgneal@516 39 command.execute()
bgneal@516 40
bgneal@516 41 # Execute our forum cleanup command to delete old last visit records.
bgneal@516 42
bgneal@516 43 command = ForumCleanup()
bgneal@516 44 command.execute()