changeset 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 ae89ba801e8b
children 666147a2cc08
files gpp/core/tasks.py gpp/settings/base.py
diffstat 2 files changed, 33 insertions(+), 1 deletions(-) [+]
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()
--- a/gpp/settings/base.py	Wed Dec 14 02:41:15 2011 +0000
+++ b/gpp/settings/base.py	Thu Dec 15 00:59:32 2011 +0000
@@ -219,7 +219,11 @@
     "potd": {
         "task": "potd.tasks.pick_potd",
         "schedule": crontab(minute=0, hour=0),
-    }
+    },
+    "cleanup": {
+        "task": "core.tasks.cleanup",
+        "schedule": crontab(minute=0, hour=1),
+    },
 }
 
 #######################################################################