Mercurial > public > sg101
view wiki/tasks.py @ 1157:e4f2d6a4b401
Rework S3 connection logic for latest versions of Python 2.7.
Had to make these changes for Ubuntu 16.04. Seems backward compatible
with production.
author | Brian Neal <bgneal@gmail.com> |
---|---|
date | Thu, 19 Jan 2017 18:35:53 -0600 |
parents | aeafbf3ecebf |
children |
line wrap: on
line source
""" Celery tasks for the wiki app. """ from __future__ import absolute_import import datetime import logging import time from celery import shared_task from django.conf import settings import redis from core.services import get_redis_connection logger = logging.getLogger(__name__) @shared_task def expire_cookies(): """ Periodically run this task to remove expired cookies from the Redis set that is shared between this Django application & the MoinMoin wiki for authentication. """ now = datetime.datetime.utcnow() cutoff = now - datetime.timedelta(seconds=settings.WIKI_COOKIE_AGE) min_score = time.mktime(cutoff.utctimetuple()) conn = get_redis_connection() set_name = settings.WIKI_REDIS_SET try: count = conn.zcard(set_name) except redis.RedisError: logger.error("Error getting zcard") return try: removed = conn.zremrangebyscore(set_name, 0.0, min_score) except redis.RedisError: logger.error("Error removing by score") return total = count - removed logger.info("Expire wiki cookies: removed %d, total is now %d", removed, total)