Mercurial > public > sg101
comparison core/tasks.py @ 581:ee87ea74d46b
For Django 1.4, rearranged project structure for new manage.py.
author | Brian Neal <bgneal@gmail.com> |
---|---|
date | Sat, 05 May 2012 17:10:48 -0500 |
parents | gpp/core/tasks.py@f72ace06658a |
children | 53a56d19568c |
comparison
equal
deleted
inserted
replaced
580:c525f3e0b5d0 | 581:ee87ea74d46b |
---|---|
1 """ | |
2 Celery tasks for the core application. | |
3 | |
4 """ | |
5 from celery.task import task | |
6 import django.core.mail | |
7 | |
8 import core.whos_online | |
9 | |
10 | |
11 @task | |
12 def add(x, y): | |
13 """ | |
14 It is useful to have a test task laying around. This is it. | |
15 | |
16 """ | |
17 return x + y | |
18 | |
19 | |
20 @task | |
21 def send_mail(subject, message, from_email, recipient_list, **kwargs): | |
22 """ | |
23 A task to send mail via Django. | |
24 | |
25 """ | |
26 django.core.mail.send_mail(subject, message, from_email, recipient_list, | |
27 **kwargs) | |
28 | |
29 | |
30 @task | |
31 def cleanup(): | |
32 """ | |
33 A task to perform site-wide cleanup actions. | |
34 | |
35 """ | |
36 # These imports, when placed at the top of the module, caused all kinds of | |
37 # import problems when running on the production server (Python 2.5 and | |
38 # mod_wsgi). Moving them here worked around that problem. | |
39 | |
40 from django.core.management.commands.cleanup import Command as CleanupCommand | |
41 from forums.management.commands.forum_cleanup import Command as ForumCleanup | |
42 | |
43 # Execute Django's cleanup command (deletes old sessions). | |
44 | |
45 command = CleanupCommand() | |
46 command.execute() | |
47 | |
48 # Execute our forum cleanup command to delete old last visit records. | |
49 | |
50 command = ForumCleanup() | |
51 command.execute() | |
52 | |
53 | |
54 @task | |
55 def max_users(): | |
56 """ | |
57 Run the periodic task to calculate the who's online max users/visitors | |
58 statistics. | |
59 | |
60 """ | |
61 core.whos_online.max_users() |