Tivix / django-cron

Write cron business logic as a Python class and let this app do the rest! It enables Django projects to schedule cron tasks, tracks their success / failures, manages contention (via a cache) etc. Basically takes care of all the boring work for you :-)
www.tivix.com
MIT License
900 stars 193 forks source link

Remove succeeded cron job #104

Closed anrw closed 2 years ago

anrw commented 7 years ago

Hey all, Need your advice on best practice :)

I am running cron job every minute to check if there is anything I need users to notify. If so, I send them push notifications. Everything works great, however it logs me 1440 database rows a day, which I think is not great. Is it a way to remove row immediately if cron job has finished with success?

Thank you in advance, Andrew

evenicoulddoit commented 7 years ago

Hi @anrw - I think our business want something similar. I've already got a fork of Django Cron which adds some other features and I'll probably make something for this soon if you're interested?

anrw commented 7 years ago

Thanks, @evenicoulddoit! I am definitely interested, how can I find it?

tab-cmd commented 7 years ago

@anrw we generally felt log management should be left to the dev. However, ...

@evenicoulddoit We could be interested in implementing something that is default off, but when turned on and running crons it would check for some amount of successful or overall logs defined by the user then delete. Let me know if this is something you'd be interested in contributing to. Otherwise it will go to our wishlist for now.

tab-cmd commented 7 years ago

something like we do with this time based deletion

def clear_old_log_entries(): """ Removes older log entries, if the appropriate setting has been set """ if hasattr(settings, 'DJANGO_CRON_DELETE_LOGS_OLDER_THAN'): delta = timedelta(days=settings.DJANGO_CRON_DELETE_LOGS_OLDER_THAN) CronJobLog.objects.filter(end_time__lt=get_current_time() - delta).delete()`

cveilleux commented 6 years ago

I've shared a solution that can help with this issue in #144