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

Exit on follow by inspecting the current log line #207

Merged
merged 4 commits into from
Oct 2, 2018
Merged

Conversation

ReDeiPirati
Copy link
Contributor

failure = "[failed] Task execution failed"
shutdown = "[shutdown] Task execution cancelled"
timeout = "[timeout] Task execution cancelled"
termination_list = [success, failure, shutdown, timeout]
Copy link
Contributor

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.

Copy link
Contributor

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.

SUCCESS_OUTPUT = "[success] Finished execution"
FAILURE_OUTPUT = "[failed] Task execution failed"
..
TERMINATION_OUTPUT_LIST = [SUCCESS_OUTPUT, FAILURE_OUTPUT, ..]

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):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

for simplification, you can just write return any(terminal_line in log_output_line for terminal_line in termination_list).

# 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, termination_list)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This could be simplified as:

job_terminated = print_output in termination_list

Then you can remove the extra function call here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I cannot go for job_terminated = print_output in termination_list, because it's conditioning for a perfect match while in this case, I'm performing a substring match.

failure = "[failed] Task execution failed"
shutdown = "[shutdown] Task execution cancelled"
timeout = "[timeout] Task execution cancelled"
termination_list = [success, failure, shutdown, timeout]
Copy link
Contributor

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.

SUCCESS_OUTPUT = "[success] Finished execution"
FAILURE_OUTPUT = "[failed] Task execution failed"
..
TERMINATION_OUTPUT_LIST = [SUCCESS_OUTPUT, FAILURE_OUTPUT, ..]

@narenst narenst merged commit 1e3fe30 into master Oct 2, 2018
@narenst narenst deleted the exit-on-follow branch October 2, 2018 21:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants