mirror of
https://github.com/ansible/awx.git
synced 2026-01-13 02:50:02 -03:30
Implementing tower cleanup task for cleaning up facts
This commit is contained in:
parent
be7f27af0d
commit
22acd51650
@ -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)
|
||||
|
||||
|
||||
@ -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:
|
||||
|
||||
@ -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'])
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user