annotate core/tasks.py @ 661:15dbe0ccda95
Prevent exceptions when viewing downloads in the admin when the file
doesn't exist on the filesystem. This is usually seen in development
but can also happen in production if the file is missing.
author |
Brian Neal <bgneal@gmail.com> |
date |
Tue, 14 May 2013 21:02:47 -0500 |
parents |
ee87ea74d46b |
children |
53a56d19568c |
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@519
|
8 import core.whos_online
|
bgneal@519
|
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@518
|
36 # These imports, when placed at the top of the module, caused all kinds of
|
bgneal@518
|
37 # import problems when running on the production server (Python 2.5 and
|
bgneal@518
|
38 # mod_wsgi). Moving them here worked around that problem.
|
bgneal@518
|
39
|
bgneal@517
|
40 from django.core.management.commands.cleanup import Command as CleanupCommand
|
bgneal@517
|
41 from forums.management.commands.forum_cleanup import Command as ForumCleanup
|
bgneal@518
|
42
|
bgneal@516
|
43 # Execute Django's cleanup command (deletes old sessions).
|
bgneal@516
|
44
|
bgneal@516
|
45 command = CleanupCommand()
|
bgneal@516
|
46 command.execute()
|
bgneal@516
|
47
|
bgneal@516
|
48 # Execute our forum cleanup command to delete old last visit records.
|
bgneal@516
|
49
|
bgneal@516
|
50 command = ForumCleanup()
|
bgneal@516
|
51 command.execute()
|
bgneal@519
|
52
|
bgneal@519
|
53
|
bgneal@519
|
54 @task
|
bgneal@519
|
55 def max_users():
|
bgneal@519
|
56 """
|
bgneal@519
|
57 Run the periodic task to calculate the who's online max users/visitors
|
bgneal@519
|
58 statistics.
|
bgneal@519
|
59
|
bgneal@519
|
60 """
|
bgneal@519
|
61 core.whos_online.max_users()
|