collect events based on last ship, not collection

This commit is contained in:
Christian Adams
2019-05-14 17:14:44 -04:00
parent 6bc1856658
commit d0e160a037

View File

@@ -66,8 +66,6 @@ def gather(dest=None, module=None):
state = TowerAnalyticsState.get_solo() state = TowerAnalyticsState.get_solo()
last_run = state.last_run last_run = state.last_run
logger.debug("Last analytics run was: {}".format(last_run)) logger.debug("Last analytics run was: {}".format(last_run))
state.last_run = run_now
state.save()
max_interval = now() - timedelta(days=7) max_interval = now() - timedelta(days=7)
if last_run < max_interval or not last_run: if last_run < max_interval or not last_run:
@@ -132,6 +130,12 @@ def ship(path):
] ]
output = smart_str(subprocess.check_output(cmd, timeout=60 * 5)) output = smart_str(subprocess.check_output(cmd, timeout=60 * 5))
logger.debug(output) 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: