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

Produce proper exit status in case image has been built with timeout #35282

Merged
merged 1 commit into from
Oct 31, 2023
Merged
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
23 changes: 21 additions & 2 deletions dev/breeze/src/airflow_breeze/commands/ci_image_commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,20 @@ def kill_process_group(build_process_group_id: int):
pass


def get_exitcode(status: int) -> int:
# In Python 3.9+ we will be able to use
# os.waitstatus_to_exitcode(status) - see https://github.com/python/cpython/issues/84275
# but until then we need to do this ugly conversion
if os.WIFSIGNALED(status):
return -os.WTERMSIG(status)
elif os.WIFEXITED(status):
return os.WEXITSTATUS(status)
elif os.WIFSTOPPED(status):
return -os.WSTOPSIG(status)
else:
return 1


@ci_image.command(name="build")
@option_python
@option_run_in_parallel
Expand Down Expand Up @@ -277,8 +291,13 @@ def run_build(ci_image_params: BuildCiParams) -> None:
atexit.register(kill_process_group, pid)
signal.signal(signal.SIGALRM, handler)
signal.alarm(build_timeout_minutes * 60)
os.waitpid(pid, 0)
return
child_pid, status = os.waitpid(pid, 0)
exit_code = get_exitcode(status)
if exit_code:
get_console().print(f"[error]Exiting with exit code {exit_code}")
else:
get_console().print(f"[success]Exiting with exit code {exit_code}")
sys.exit(exit_code)
else:
# turn us into a process group leader
os.setpgid(0, 0)
Expand Down
Loading