Mercurial > public > sg101
annotate core/tasks.py @ 943:cf9918328c64
Haystack tweaks for Django 1.7.7.
I had to upgrade to Haystack 2.3.1 to get it to work with Django
1.7.7. I also had to update the Xapian backend. But I ran into
problems.
On my laptop anyway (Ubuntu 14.0.4), xapian gets mad when search terms
are greater than 245 chars (or something) when indexing. So I created
a custom field that would simply omit terms greater than 64 chars and
used this field everywhere I previously used a CharField.
Secondly, the custom search form was broken now. Something changed in
the Xapian backend and exact searches stopped working. Fortunately the
auto_query (which I was using originally and broke during an upgrade)
started working again. So I cut the search form back over to doing an
auto_query. I kept the form the same (3 fields) because I didn't want
to change the form and I think it's better that way.
author | Brian Neal <bgneal@gmail.com> |
---|---|
date | Wed, 13 May 2015 20:25:07 -0500 |
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() |