Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reduce log noise from next run being in past #15670

Open
wants to merge 1 commit into
base: devel
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@
# 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 @@
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 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 @@
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 @@

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
Loading