diff gpp/core/tasks.py @ 516:beda97542da8

For #194, add a celery beat task for Django & forum cleanup.
author Brian Neal <bgneal@gmail.com>
date Thu, 15 Dec 2011 00:59:32 +0000
parents 9e7ae8462f3f
children 666147a2cc08
line wrap: on
line diff
--- a/gpp/core/tasks.py	Wed Dec 14 02:41:15 2011 +0000
+++ b/gpp/core/tasks.py	Thu Dec 15 00:59:32 2011 +0000
@@ -4,13 +4,41 @@
 """
 from celery.task import task
 import django.core.mail
+from django.core.management.commands.cleanup import Command as CleanupCommand
+from forums.management.commands.forum_cleanup import Command as ForumCleanup
 
 
 @task
 def add(x, y):
+    """
+    It is useful to have a test task laying around. This is it.
+
+    """
     return x + y
 
+
 @task
 def send_mail(subject, message, from_email, recipient_list, **kwargs):
+    """
+    A task to send mail via Django.
+
+    """
     django.core.mail.send_mail(subject, message, from_email, recipient_list,
             **kwargs)
+
+
+@task
+def cleanup():
+    """
+    A task to perform site-wide cleanup actions.
+
+    """
+    # Execute Django's cleanup command (deletes old sessions).
+
+    command = CleanupCommand()
+    command.execute()
+
+    # Execute our forum cleanup command to delete old last visit records.
+
+    command = ForumCleanup()
+    command.execute()