mirror of
https://github.com/ansible/awx.git
synced 2026-02-26 15:36:04 -03:30
Implementing tower cleanup task for cleaning up facts
This commit is contained in:
@@ -4,12 +4,12 @@
|
|||||||
# Python
|
# Python
|
||||||
import re
|
import re
|
||||||
from dateutil.relativedelta import relativedelta
|
from dateutil.relativedelta import relativedelta
|
||||||
from datetime import datetime
|
|
||||||
from optparse import make_option
|
from optparse import make_option
|
||||||
|
|
||||||
# Django
|
# Django
|
||||||
from django.core.management.base import BaseCommand, CommandError
|
from django.core.management.base import BaseCommand, CommandError
|
||||||
from django.db import transaction
|
from django.db import transaction
|
||||||
|
from django.utils.timezone import now
|
||||||
|
|
||||||
# AWX
|
# AWX
|
||||||
from awx.fact.models.fact import * # noqa
|
from awx.fact.models.fact import * # noqa
|
||||||
@@ -72,7 +72,7 @@ class CleanupFacts(object):
|
|||||||
older_than and granularity are of type relativedelta
|
older_than and granularity are of type relativedelta
|
||||||
'''
|
'''
|
||||||
def run(self, older_than, granularity):
|
def run(self, older_than, granularity):
|
||||||
t = datetime.now()
|
t = now()
|
||||||
deleted_count = self.cleanup(t - older_than, granularity)
|
deleted_count = self.cleanup(t - older_than, granularity)
|
||||||
print("Deleted %d facts." % deleted_count)
|
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_jobs', _('Remove jobs older than a certain number of days')),
|
||||||
('cleanup_activitystream', _('Remove activity stream entries 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_deleted', _('Purge previously deleted items from the database')),
|
||||||
|
('cleanup_facts', _('Purge and/or reduce the granularity of system tracking data')),
|
||||||
]
|
]
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
|
|||||||
@@ -1352,10 +1352,15 @@ class RunSystemJob(BaseTask):
|
|||||||
args = ['awx-manage', system_job.job_type]
|
args = ['awx-manage', system_job.job_type]
|
||||||
try:
|
try:
|
||||||
json_vars = json.loads(system_job.extra_vars)
|
json_vars = json.loads(system_job.extra_vars)
|
||||||
if 'days' in json_vars:
|
if 'days' in json_vars and system_job.job_type != 'cleanup_facts':
|
||||||
args.extend(['--days', str(json_vars['days'])])
|
args.extend(['--days', str(json_vars.get('days', 60))])
|
||||||
if system_job.job_type == 'cleanup_jobs':
|
if system_job.job_type == 'cleanup_jobs':
|
||||||
args.extend(['--jobs', '--project-updates', '--inventory-updates', '--management-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
|
# Keeping this around in case we want to break this out
|
||||||
# if 'jobs' in json_vars and json_vars['jobs']:
|
# if 'jobs' in json_vars and json_vars['jobs']:
|
||||||
# args.extend(['--jobs'])
|
# args.extend(['--jobs'])
|
||||||
|
|||||||
Reference in New Issue
Block a user