-
Notifications
You must be signed in to change notification settings - Fork 34
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
Exit on follow by inspecting the current log line #207
Merged
Merged
Changes from 1 commit
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -182,12 +182,33 @@ def get_log_id(job_id): | |
return instance_log_id | ||
|
||
|
||
def check_job_termination_line(log_output_line): | ||
""" | ||
Get Job termination by inspecting if any of the termination log lines is detected | ||
in the current log output line. | ||
""" | ||
job_terminated = False | ||
success = "[success] Finished execution" | ||
failure = "[failed] Task execution failed" | ||
shutdown = "[shutdown] Task execution cancelled" | ||
timeout = "[timeout] Task execution cancelled" | ||
termination_list = [success, failure, shutdown, timeout] | ||
|
||
if any(terminal_line in log_output_line for terminal_line in termination_list): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. for simplification, you can just write |
||
job_terminated = True | ||
|
||
return job_terminated | ||
|
||
|
||
def follow_logs(instance_log_id, sleep_duration=1): | ||
cur_idx = 0 | ||
while True: | ||
job_terminated = False | ||
while not job_terminated: | ||
# Get the logs in a loop and log the new lines | ||
log_file_contents = ResourceClient().get_content(instance_log_id) | ||
print_output = log_file_contents[cur_idx:] | ||
# Get the status of the Job from the current log line | ||
job_terminated = check_job_termination_line(print_output) | ||
cur_idx += len(print_output) | ||
sys.stdout.write(print_output) | ||
sleep(sleep_duration) | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
better move this list creation outside so we are not creating a new list on every function call.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agreed, move this outside the function to the top of this file. Also since these are constants use capitalized variable names for easy identification.