1
0
mirror of https://github.com/ansible/awx.git synced 2024-10-31 23:51:09 +03:00

Delete collection tarball when no longer needed

* Delete after shipping it
   * Delete when ship() fails
This commit is contained in:
Christian Adams 2019-06-27 16:46:54 -04:00
parent 4470e9ca26
commit e72b2fac6d

View File

@ -119,24 +119,28 @@ def ship(path):
""" """
Ship gathered metrics via the Insights agent Ship gathered metrics via the Insights agent
""" """
agent = 'insights-client'
if shutil.which(agent) is None:
logger.error('could not find {} on PATH'.format(agent))
return
logger.debug('shipping analytics file: {}'.format(path))
try: try:
cmd = [ agent = 'insights-client'
agent, '--payload', path, '--content-type', settings.INSIGHTS_AGENT_MIME if shutil.which(agent) is None:
] logger.error('could not find {} on PATH'.format(agent))
output = smart_str(subprocess.check_output(cmd, timeout=60 * 5)) return
logger.debug(output) logger.debug('shipping analytics file: {}'.format(path))
# reset the `last_run` when data is shipped try:
run_now = now() cmd = [
state = TowerAnalyticsState.get_solo() agent, '--payload', path, '--content-type', settings.INSIGHTS_AGENT_MIME
state.last_run = run_now ]
state.save() output = smart_str(subprocess.check_output(cmd, timeout=60 * 5))
logger.debug(output)
# reset the `last_run` when data is shipped
run_now = now()
state = TowerAnalyticsState.get_solo()
state.last_run = run_now
state.save()
except subprocess.CalledProcessError: except subprocess.CalledProcessError:
logger.exception('{} failure:'.format(cmd)) logger.exception('{} failure:'.format(cmd))
except subprocess.TimeoutExpired: except subprocess.TimeoutExpired:
logger.exception('{} timeout:'.format(cmd)) logger.exception('{} timeout:'.format(cmd))
finally:
# cleanup tar.gz
os.remove(path)