annotate gpp/core/tasks.py @ 518:5171a5e9353b
For #194, add a celery task for purging deleted private messages.
author |
Brian Neal <bgneal@gmail.com> |
date |
Fri, 16 Dec 2011 01:17:35 +0000 |
parents |
666147a2cc08 |
children |
f72ace06658a |
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@513
|
7
|
bgneal@513
|
8
|
bgneal@513
|
9 @task
|
bgneal@513
|
10 def add(x, y):
|
bgneal@516
|
11 """
|
bgneal@516
|
12 It is useful to have a test task laying around. This is it.
|
bgneal@516
|
13
|
bgneal@516
|
14 """
|
bgneal@513
|
15 return x + y
|
bgneal@513
|
16
|
bgneal@516
|
17
|
bgneal@513
|
18 @task
|
bgneal@513
|
19 def send_mail(subject, message, from_email, recipient_list, **kwargs):
|
bgneal@516
|
20 """
|
bgneal@516
|
21 A task to send mail via Django.
|
bgneal@516
|
22
|
bgneal@516
|
23 """
|
bgneal@513
|
24 django.core.mail.send_mail(subject, message, from_email, recipient_list,
|
bgneal@513
|
25 **kwargs)
|
bgneal@516
|
26
|
bgneal@516
|
27
|
bgneal@516
|
28 @task
|
bgneal@516
|
29 def cleanup():
|
bgneal@516
|
30 """
|
bgneal@516
|
31 A task to perform site-wide cleanup actions.
|
bgneal@516
|
32
|
bgneal@516
|
33 """
|
bgneal@518
|
34 # These imports, when placed at the top of the module, caused all kinds of
|
bgneal@518
|
35 # import problems when running on the production server (Python 2.5 and
|
bgneal@518
|
36 # mod_wsgi). Moving them here worked around that problem.
|
bgneal@518
|
37
|
bgneal@517
|
38 from django.core.management.commands.cleanup import Command as CleanupCommand
|
bgneal@517
|
39 from forums.management.commands.forum_cleanup import Command as ForumCleanup
|
bgneal@518
|
40
|
bgneal@516
|
41 # Execute Django's cleanup command (deletes old sessions).
|
bgneal@516
|
42
|
bgneal@516
|
43 command = CleanupCommand()
|
bgneal@516
|
44 command.execute()
|
bgneal@516
|
45
|
bgneal@516
|
46 # Execute our forum cleanup command to delete old last visit records.
|
bgneal@516
|
47
|
bgneal@516
|
48 command = ForumCleanup()
|
bgneal@516
|
49 command.execute()
|