Skip to content

Instantly share code, notes, and snippets.

@maxvyaznikov
Created May 27, 2013 16:50
Show Gist options
  • Save maxvyaznikov/5658055 to your computer and use it in GitHub Desktop.
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.
# 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