FrankYang0529 commented on code in PR #71305:
URL: https://github.com/apache/airflow/pull/71305#discussion_r3801292572
##########
dev/breeze/src/airflow_breeze/utils/gh_workflow_utils.py:
##########
@@ -122,16 +126,41 @@ def get_workflow_run_id(workflow_name: str, repo: str) ->
int:
runs_data = result.stdout.strip()
if not runs_data:
- console_print("[red]No workflow runs found.[/red]")
- sys.exit(1)
+ return None
- run_id = json.loads(runs_data)[0].get("databaseId")
+ runs = json.loads(runs_data)
+ return runs[0].get("databaseId") if runs else None
- console_print(
- f"[blue]Running workflow {workflow_name} at
https://github.com/{repo}/actions/runs/{run_id}[/blue]",
- )
- return run_id
+def wait_for_new_workflow_run(workflow_name: str, repo: str, previous_run_id:
int | None) -> int:
+ """
+ Wait until a run newer than ``previous_run_id`` shows up and return its id.
+
+ Run ids increase monotonically, so anything above the id observed just
before the dispatch is
+ the run we started. Taking whatever run is newest would instead latch onto
an unrelated one -
+ a scheduled run, or another maintainer's - whenever ours has not
registered yet, and report
+ that run's result as ours.
+
+ :param workflow_name: The name of the workflow that was dispatched.
+ :param repo: The repository in the format 'owner/repo'.
+ :param previous_run_id: The newest run id seen before dispatching, or None
if there was none.
+ """
+ deadline = time.monotonic() + NEW_RUN_TIMEOUT_SECONDS
+ while True:
+ run_id = get_latest_workflow_run_id(workflow_name, repo)
Review Comment:
`get_latest_workflow_run_id` checks `returncode`. If there is temporary
network failure, we need to rerun the workflow. Since we already have retry
mechanism here, how about catch the exception and retry the command?
##########
dev/breeze/src/airflow_breeze/utils/gh_workflow_utils.py:
##########
@@ -122,16 +126,41 @@ def get_workflow_run_id(workflow_name: str, repo: str) ->
int:
runs_data = result.stdout.strip()
if not runs_data:
- console_print("[red]No workflow runs found.[/red]")
- sys.exit(1)
+ return None
- run_id = json.loads(runs_data)[0].get("databaseId")
+ runs = json.loads(runs_data)
+ return runs[0].get("databaseId") if runs else None
- console_print(
- f"[blue]Running workflow {workflow_name} at
https://github.com/{repo}/actions/runs/{run_id}[/blue]",
- )
- return run_id
+def wait_for_new_workflow_run(workflow_name: str, repo: str, previous_run_id:
int | None) -> int:
+ """
+ Wait until a run newer than ``previous_run_id`` shows up and return its id.
+
+ Run ids increase monotonically, so anything above the id observed just
before the dispatch is
+ the run we started. Taking whatever run is newest would instead latch onto
an unrelated one -
+ a scheduled run, or another maintainer's - whenever ours has not
registered yet, and report
+ that run's result as ours.
+
+ :param workflow_name: The name of the workflow that was dispatched.
+ :param repo: The repository in the format 'owner/repo'.
+ :param previous_run_id: The newest run id seen before dispatching, or None
if there was none.
+ """
+ deadline = time.monotonic() + NEW_RUN_TIMEOUT_SECONDS
+ while True:
+ run_id = get_latest_workflow_run_id(workflow_name, repo)
+ if run_id is not None and (previous_run_id is None or run_id >
previous_run_id):
Review Comment:
`get_latest_workflow_run_id` returns the latest run id. However,
airflow-site also runs build.yaml workflow if there is pull request or push to
master. How about adding `--event workflow_dispatch` to `gh run list` command,
so we can avoid the race condition.
https://github.com/apache/airflow-site/blob/7d6312026ff4cd4f611be7dad6980fd78b269667/.github/workflows/build.yml#L18-L24
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]