Skip to content

Instantly share code, notes, and snippets.

@arajkumar
Created January 5, 2021 14:40
Show Gist options
  • Save arajkumar/0d2fa8b42fe975027a24c26e425524ef to your computer and use it in GitHub Desktop.
Save arajkumar/0d2fa8b42fe975027a24c26e425524ef to your computer and use it in GitHub Desktop.
def cleanup_db_tables(self):
"""Cleanup RDS data tables on a periodic basis."""
def clean_celery_taskmeta():
num_days = os.environ.get('KEEP_DB_META_NUM_DAYS', '30')
self.cleanup_tables('celery_taskmeta', 'date_done', num_days)
def clean_worker_results()
num_days = os.environ.get('KEEP_WORKER_RESULT_NUM_DAYS', '30')
self.cleanup_tables('worker_results', 'ended_at', num_days)
...
cleanup_tables = [clean_celery_taskmeta, clean_worker_results, ]
for clean in cleanup_db_tables:
try:
clean()
except Exception as e:
logger.error("cleanup failed for %s with exception %r", clean.__name__, e)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment