Mercurial > public > sg101
annotate gpp/core/tasks.py @ 517:666147a2cc08
Moved the imports from the top of the file into the task function. This seemed to prevent some strange import errors that only occurred on the production server. I don't know if the problems were related to mod_wsgi or Python 2.5 or what.
author | Brian Neal <bgneal@gmail.com> |
---|---|
date | Thu, 15 Dec 2011 02:49:16 +0000 |
parents | beda97542da8 |
children | 5171a5e9353b |
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@517 | 34 from django.core.management.commands.cleanup import Command as CleanupCommand |
bgneal@517 | 35 from forums.management.commands.forum_cleanup import Command as ForumCleanup |
bgneal@516 | 36 # Execute Django's cleanup command (deletes old sessions). |
bgneal@516 | 37 |
bgneal@516 | 38 command = CleanupCommand() |
bgneal@516 | 39 command.execute() |
bgneal@516 | 40 |
bgneal@516 | 41 # Execute our forum cleanup command to delete old last visit records. |
bgneal@516 | 42 |
bgneal@516 | 43 command = ForumCleanup() |
bgneal@516 | 44 command.execute() |