# HG changeset patch # User Brian Neal # Date 1323910772 0 # Node ID beda97542da8393e01e4b3bdb3131476cc3b6e8c # Parent ae89ba801e8b95dbc94db50016c2dccbef693121 For #194, add a celery beat task for Django & forum cleanup. diff -r ae89ba801e8b -r beda97542da8 gpp/core/tasks.py --- 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() diff -r ae89ba801e8b -r beda97542da8 gpp/settings/base.py --- 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), + }, } #######################################################################