comparison 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
comparison
equal deleted inserted replaced
515:ae89ba801e8b 516:beda97542da8
2 Celery tasks for the core application. 2 Celery tasks for the core application.
3 3
4 """ 4 """
5 from celery.task import task 5 from celery.task import task
6 import django.core.mail 6 import django.core.mail
7 from django.core.management.commands.cleanup import Command as CleanupCommand
8 from forums.management.commands.forum_cleanup import Command as ForumCleanup
7 9
8 10
9 @task 11 @task
10 def add(x, y): 12 def add(x, y):
13 """
14 It is useful to have a test task laying around. This is it.
15
16 """
11 return x + y 17 return x + y
18
12 19
13 @task 20 @task
14 def send_mail(subject, message, from_email, recipient_list, **kwargs): 21 def send_mail(subject, message, from_email, recipient_list, **kwargs):
22 """
23 A task to send mail via Django.
24
25 """
15 django.core.mail.send_mail(subject, message, from_email, recipient_list, 26 django.core.mail.send_mail(subject, message, from_email, recipient_list,
16 **kwargs) 27 **kwargs)
28
29
30 @task
31 def cleanup():
32 """
33 A task to perform site-wide cleanup actions.
34
35 """
36 # Execute Django's cleanup command (deletes old sessions).
37
38 command = CleanupCommand()
39 command.execute()
40
41 # Execute our forum cleanup command to delete old last visit records.
42
43 command = ForumCleanup()
44 command.execute()