Mercurial > public > sg101
annotate core/tasks.py @ 1006:842c1343061c
Merge.
author | Brian Neal <bgneal@gmail.com> |
---|---|
date | Thu, 26 Nov 2015 23:18:15 -0600 |
parents | 79a71b9d0a2a |
children |
rev | line source |
---|---|
bgneal@513 | 1 """ |
bgneal@513 | 2 Celery tasks for the core application. |
bgneal@513 | 3 |
bgneal@513 | 4 """ |
bgneal@750 | 5 from __future__ import absolute_import |
bgneal@750 | 6 |
bgneal@892 | 7 import django.core.mail |
bgneal@750 | 8 from celery import shared_task |
bgneal@513 | 9 |
bgneal@519 | 10 import core.whos_online |
bgneal@519 | 11 |
bgneal@513 | 12 |
bgneal@750 | 13 @shared_task |
bgneal@892 | 14 def send_mail(**kwargs): |
bgneal@516 | 15 """ |
bgneal@516 | 16 A task to send mail via Django. |
bgneal@516 | 17 |
bgneal@892 | 18 kwargs must be a dict of keyword arguments for an EmailMessage. |
bgneal@892 | 19 |
bgneal@516 | 20 """ |
bgneal@892 | 21 msg = django.core.mail.EmailMessage(**kwargs) |
bgneal@892 | 22 msg.send() |
bgneal@516 | 23 |
bgneal@516 | 24 |
bgneal@750 | 25 @shared_task |
bgneal@516 | 26 def cleanup(): |
bgneal@516 | 27 """ |
bgneal@516 | 28 A task to perform site-wide cleanup actions. |
bgneal@516 | 29 |
bgneal@516 | 30 """ |
bgneal@518 | 31 # These imports, when placed at the top of the module, caused all kinds of |
bgneal@518 | 32 # import problems when running on the production server (Python 2.5 and |
bgneal@518 | 33 # mod_wsgi). Moving them here worked around that problem. |
bgneal@518 | 34 |
bgneal@681 | 35 from django.contrib.sessions.management.commands import clearsessions |
bgneal@681 | 36 from forums.management.commands import forum_cleanup |
bgneal@518 | 37 |
bgneal@681 | 38 # Cleanup old sessions |
bgneal@516 | 39 |
bgneal@681 | 40 command = clearsessions.Command() |
bgneal@516 | 41 command.execute() |
bgneal@516 | 42 |
bgneal@516 | 43 # Execute our forum cleanup command to delete old last visit records. |
bgneal@516 | 44 |
bgneal@681 | 45 command = forum_cleanup.Command() |
bgneal@516 | 46 command.execute() |
bgneal@519 | 47 |
bgneal@519 | 48 |
bgneal@750 | 49 @shared_task |
bgneal@519 | 50 def max_users(): |
bgneal@519 | 51 """ |
bgneal@519 | 52 Run the periodic task to calculate the who's online max users/visitors |
bgneal@519 | 53 statistics. |
bgneal@519 | 54 |
bgneal@519 | 55 """ |
bgneal@519 | 56 core.whos_online.max_users() |