Created
May 27, 2013 16:50
-
-
Save maxvyaznikov/5658055 to your computer and use it in GitHub Desktop.
Working with django-cron, should forever have near this CronJob.
Shortly, this CronJob erased (drops/remove/delete) old log records from django-cron from DB.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# coding=utf-8 | |
from datetime import date, timedelta | |
import logging | |
from django_cron import CronJobBase, Schedule | |
from django_cron.models import CronJobLog | |
logger = logging.getLogger('captcha') | |
class DropLogs(CronJobBase): | |
RUN_EVERY_MINS = 60*24*7 # week | |
schedule = Schedule(run_every_mins=RUN_EVERY_MINS) | |
code = 'drop_logs' | |
def do(self): | |
CronJobLog.objects.filter(start_time__lt=date.today()-timedelta(minutes=self.RUN_EVERY_MINS)).delete() | |
logger.info('Logs dropped') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment