From 22acd51650892d165cb9dbc4b1fb2298dccc3cf0 Mon Sep 17 00:00:00 2001 From: Matthew Jones Date: Fri, 24 Apr 2015 14:15:25 -0400 Subject: [PATCH] Implementing tower cleanup task for cleaning up facts --- awx/main/management/commands/cleanup_facts.py | 4 ++-- awx/main/models/jobs.py | 1 + awx/main/tasks.py | 9 +++++++-- 3 files changed, 10 insertions(+), 4 deletions(-) diff --git a/awx/main/management/commands/cleanup_facts.py b/awx/main/management/commands/cleanup_facts.py index cd427f082a..d127b52c52 100644 --- a/awx/main/management/commands/cleanup_facts.py +++ b/awx/main/management/commands/cleanup_facts.py @@ -4,12 +4,12 @@ # Python import re from dateutil.relativedelta import relativedelta -from datetime import datetime from optparse import make_option # Django from django.core.management.base import BaseCommand, CommandError from django.db import transaction +from django.utils.timezone import now # AWX from awx.fact.models.fact import * # noqa @@ -72,7 +72,7 @@ class CleanupFacts(object): older_than and granularity are of type relativedelta ''' def run(self, older_than, granularity): - t = datetime.now() + t = now() deleted_count = self.cleanup(t - older_than, granularity) print("Deleted %d facts." % deleted_count) diff --git a/awx/main/models/jobs.py b/awx/main/models/jobs.py index 78b45f5d12..0ab8d0ee67 100644 --- a/awx/main/models/jobs.py +++ b/awx/main/models/jobs.py @@ -945,6 +945,7 @@ class SystemJobOptions(BaseModel): ('cleanup_jobs', _('Remove jobs older than a certain number of days')), ('cleanup_activitystream', _('Remove activity stream entries older than a certain number of days')), ('cleanup_deleted', _('Purge previously deleted items from the database')), + ('cleanup_facts', _('Purge and/or reduce the granularity of system tracking data')), ] class Meta: diff --git a/awx/main/tasks.py b/awx/main/tasks.py index adf60f9516..3e346861d4 100644 --- a/awx/main/tasks.py +++ b/awx/main/tasks.py @@ -1352,10 +1352,15 @@ class RunSystemJob(BaseTask): args = ['awx-manage', system_job.job_type] try: json_vars = json.loads(system_job.extra_vars) - if 'days' in json_vars: - args.extend(['--days', str(json_vars['days'])]) + if 'days' in json_vars and system_job.job_type != 'cleanup_facts': + args.extend(['--days', str(json_vars.get('days', 60))]) if system_job.job_type == 'cleanup_jobs': args.extend(['--jobs', '--project-updates', '--inventory-updates', '--management-jobs']) + if system_job.job_type == 'cleanup_facts': + if 'older_than' in json_vars: + args.extend(['--older_than', str(json_vars['older_than'])]) + if 'granularity' in json_vars: + args.extend(['--granularity', str(json_vars['granularity'])]) # Keeping this around in case we want to break this out # if 'jobs' in json_vars and json_vars['jobs']: # args.extend(['--jobs'])