Mercurial > public > sg101
annotate gpp/core/tasks.py @ 519:f72ace06658a
For #194, rework the who's online and max users functions.
author | Brian Neal <bgneal@gmail.com> |
---|---|
date | Sat, 17 Dec 2011 19:29:24 +0000 |
parents | 5171a5e9353b |
children |
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() |