Mercurial > public > sg101
annotate wiki/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 | aeafbf3ecebf |
children |
rev | line source |
---|---|
bgneal@627 | 1 """ |
bgneal@627 | 2 Celery tasks for the wiki app. |
bgneal@627 | 3 |
bgneal@627 | 4 """ |
bgneal@750 | 5 from __future__ import absolute_import |
bgneal@750 | 6 |
bgneal@627 | 7 import datetime |
bgneal@627 | 8 import logging |
bgneal@627 | 9 import time |
bgneal@627 | 10 |
bgneal@750 | 11 from celery import shared_task |
bgneal@627 | 12 from django.conf import settings |
bgneal@627 | 13 import redis |
bgneal@627 | 14 |
bgneal@627 | 15 from core.services import get_redis_connection |
bgneal@627 | 16 |
bgneal@627 | 17 |
bgneal@627 | 18 logger = logging.getLogger(__name__) |
bgneal@627 | 19 |
bgneal@627 | 20 |
bgneal@750 | 21 @shared_task |
bgneal@627 | 22 def expire_cookies(): |
bgneal@627 | 23 """ |
bgneal@627 | 24 Periodically run this task to remove expired cookies from the Redis set |
bgneal@627 | 25 that is shared between this Django application & the MoinMoin wiki for |
bgneal@627 | 26 authentication. |
bgneal@627 | 27 |
bgneal@627 | 28 """ |
bgneal@627 | 29 now = datetime.datetime.utcnow() |
bgneal@627 | 30 cutoff = now - datetime.timedelta(seconds=settings.WIKI_COOKIE_AGE) |
bgneal@627 | 31 min_score = time.mktime(cutoff.utctimetuple()) |
bgneal@627 | 32 |
bgneal@627 | 33 conn = get_redis_connection() |
bgneal@627 | 34 |
bgneal@627 | 35 set_name = settings.WIKI_REDIS_SET |
bgneal@627 | 36 try: |
bgneal@627 | 37 count = conn.zcard(set_name) |
bgneal@627 | 38 except redis.RedisError: |
bgneal@627 | 39 logger.error("Error getting zcard") |
bgneal@627 | 40 return |
bgneal@627 | 41 |
bgneal@627 | 42 try: |
bgneal@627 | 43 removed = conn.zremrangebyscore(set_name, 0.0, min_score) |
bgneal@627 | 44 except redis.RedisError: |
bgneal@627 | 45 logger.error("Error removing by score") |
bgneal@627 | 46 return |
bgneal@627 | 47 |
bgneal@627 | 48 total = count - removed |
bgneal@627 | 49 logger.info("Expire wiki cookies: removed %d, total is now %d", |
bgneal@627 | 50 removed, total) |