Skip to content

Commit

Permalink
Reduce log noise from next run being in past
Browse files Browse the repository at this point in the history
  • Loading branch information
AlanCoding committed Jan 3, 2025
1 parent 9a5ed20 commit 7b75cc8
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 8 deletions.
17 changes: 11 additions & 6 deletions awx/main/dispatch/periodic.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,10 @@ def __init__(self, schedule):
# internally times are all referenced relative to startup time, add grace period
self.global_start = time.time() + 2.0

def get_and_mark_pending(self):
relative_time = time.time() - self.global_start
def get_and_mark_pending(self, reftime=None):
if reftime is None:
reftime = time.time() # mostly for tests
relative_time = reftime - self.global_start
to_run = []
for job in self.jobs:
if job.due_to_run(relative_time):
Expand All @@ -98,8 +100,10 @@ def get_and_mark_pending(self):
job.mark_run(relative_time)
return to_run

def time_until_next_run(self):
relative_time = time.time() - self.global_start
def time_until_next_run(self, reftime=None):
if reftime is None:
reftime = time.time() # mostly for tests
relative_time = reftime - self.global_start

Check warning on line 106 in awx/main/dispatch/periodic.py

View check run for this annotation

Codecov / codecov/patch

awx/main/dispatch/periodic.py#L105-L106

Added lines #L105 - L106 were not covered by tests
next_job = min(self.jobs, key=lambda j: j.next_run)
delta = next_job.next_run - relative_time
if delta <= 0.1:
Expand All @@ -115,10 +119,11 @@ def time_until_next_run(self):
def debug(self, *args, **kwargs):
data = dict()
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')
relative_time = time.time() - self.global_start
relative_time = reftime - self.global_start
data['started_time'] = start_time
data['current_time'] = now
data['current_time_relative'] = round(relative_time, 3)
Expand Down
8 changes: 6 additions & 2 deletions awx/main/dispatch/worker/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,11 @@ def run_periodic_tasks(self):
except Exception as 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()

Check warning on line 210 in awx/main/dispatch/worker/base.py

View check run for this annotation

Codecov / codecov/patch

awx/main/dispatch/worker/base.py#L210

Added line #L210 was not covered by tests

for job in self.scheduler.get_and_mark_pending(reftime=reftime):
if 'control' in job.data:
try:
job.data['control']()
Expand All @@ -222,7 +226,7 @@ def run_periodic_tasks(self):

self.listen_start = time.time()

return self.scheduler.time_until_next_run()
return self.scheduler.time_until_next_run(reftime=reftime)

Check warning on line 229 in awx/main/dispatch/worker/base.py

View check run for this annotation

Codecov / codecov/patch

awx/main/dispatch/worker/base.py#L229

Added line #L229 was not covered by tests

def run(self, *args, **kwargs):
super(AWXConsumerPG, self).run(*args, **kwargs)
Expand Down

0 comments on commit 7b75cc8

Please sign in to comment.