mirror of
https://github.com/ansible/awx.git
synced 2026-03-03 09:48:51 -03:30
Reduce log noise from next run being in past (#15670)
This commit is contained in:
@@ -88,8 +88,10 @@ class Scheduler:
|
|||||||
# internally times are all referenced relative to startup time, add grace period
|
# internally times are all referenced relative to startup time, add grace period
|
||||||
self.global_start = time.time() + 2.0
|
self.global_start = time.time() + 2.0
|
||||||
|
|
||||||
def get_and_mark_pending(self):
|
def get_and_mark_pending(self, reftime=None):
|
||||||
relative_time = time.time() - self.global_start
|
if reftime is None:
|
||||||
|
reftime = time.time() # mostly for tests
|
||||||
|
relative_time = reftime - self.global_start
|
||||||
to_run = []
|
to_run = []
|
||||||
for job in self.jobs:
|
for job in self.jobs:
|
||||||
if job.due_to_run(relative_time):
|
if job.due_to_run(relative_time):
|
||||||
@@ -98,8 +100,10 @@ class Scheduler:
|
|||||||
job.mark_run(relative_time)
|
job.mark_run(relative_time)
|
||||||
return to_run
|
return to_run
|
||||||
|
|
||||||
def time_until_next_run(self):
|
def time_until_next_run(self, reftime=None):
|
||||||
relative_time = time.time() - self.global_start
|
if reftime is None:
|
||||||
|
reftime = time.time() # mostly for tests
|
||||||
|
relative_time = reftime - self.global_start
|
||||||
next_job = min(self.jobs, key=lambda j: j.next_run)
|
next_job = min(self.jobs, key=lambda j: j.next_run)
|
||||||
delta = next_job.next_run - relative_time
|
delta = next_job.next_run - relative_time
|
||||||
if delta <= 0.1:
|
if delta <= 0.1:
|
||||||
@@ -115,10 +119,11 @@ class Scheduler:
|
|||||||
def debug(self, *args, **kwargs):
|
def debug(self, *args, **kwargs):
|
||||||
data = dict()
|
data = dict()
|
||||||
data['title'] = 'Scheduler status'
|
data['title'] = 'Scheduler status'
|
||||||
|
reftime = time.time()
|
||||||
|
|
||||||
now = datetime.fromtimestamp(time.time()).strftime('%Y-%m-%d %H:%M:%S UTC')
|
now = datetime.fromtimestamp(reftime).strftime('%Y-%m-%d %H:%M:%S UTC')
|
||||||
start_time = datetime.fromtimestamp(self.global_start).strftime('%Y-%m-%d %H:%M:%S UTC')
|
start_time = datetime.fromtimestamp(self.global_start).strftime('%Y-%m-%d %H:%M:%S UTC')
|
||||||
relative_time = time.time() - self.global_start
|
relative_time = reftime - self.global_start
|
||||||
data['started_time'] = start_time
|
data['started_time'] = start_time
|
||||||
data['current_time'] = now
|
data['current_time'] = now
|
||||||
data['current_time_relative'] = round(relative_time, 3)
|
data['current_time_relative'] = round(relative_time, 3)
|
||||||
|
|||||||
@@ -212,7 +212,11 @@ class AWXConsumerPG(AWXConsumerBase):
|
|||||||
except Exception as exc:
|
except Exception as exc:
|
||||||
logger.warning(f'Failed to save dispatcher statistics {exc}')
|
logger.warning(f'Failed to save dispatcher statistics {exc}')
|
||||||
|
|
||||||
for job in self.scheduler.get_and_mark_pending():
|
# Everything benchmarks to the same original time, so that skews due to
|
||||||
|
# runtime of the actions, themselves, do not mess up scheduling expectations
|
||||||
|
reftime = time.time()
|
||||||
|
|
||||||
|
for job in self.scheduler.get_and_mark_pending(reftime=reftime):
|
||||||
if 'control' in job.data:
|
if 'control' in job.data:
|
||||||
try:
|
try:
|
||||||
job.data['control']()
|
job.data['control']()
|
||||||
@@ -229,7 +233,7 @@ class AWXConsumerPG(AWXConsumerBase):
|
|||||||
|
|
||||||
self.listen_start = time.time()
|
self.listen_start = time.time()
|
||||||
|
|
||||||
return self.scheduler.time_until_next_run()
|
return self.scheduler.time_until_next_run(reftime=reftime)
|
||||||
|
|
||||||
def run(self, *args, **kwargs):
|
def run(self, *args, **kwargs):
|
||||||
super(AWXConsumerPG, self).run(*args, **kwargs)
|
super(AWXConsumerPG, self).run(*args, **kwargs)
|
||||||
|
|||||||
Reference in New Issue
Block a user