@@ -51,11 +51,48 @@ def upload_to_aws(bucket_name, s3_client, tarball_path, s3_file):
5151 return s3_path
5252
5353
54+ def cancel_prior_jobs_and_check_runs (
55+ non_blocking_errors ,
56+ infra_config ,
57+ config ,
58+ ):
59+ """Cancel prior unfinished jobs and check runs for the PR."""
60+ # Use a thread pool to cancel prior unfinished jobs and their associated check runs.
61+ # This process is done in parallel to save time on slow network-bound operations.
62+ with concurrent .futures .ThreadPoolExecutor (max_workers = 2 ) as executor :
63+
64+ # Submit operation: cancel prior unfinished AWS Batch jobs for the PR.
65+ cxl_batch_future = executor .submit (
66+ aws_client .cancel_prior_batch_jobs ,
67+ job_queue = infra_config ['batch_queue' ],
68+ repo_name = config ['repo_name' ],
69+ pr = config ["pull_request_number" ],
70+ )
71+
72+ # Submit operation: cancel unfinished check runs for the PR.
73+ cxl_checkrun_future = executor .submit (
74+ github_client .cancel_prior_unfinished_check_runs ,
75+ repo = config ['repo_name' ],
76+ owner = config ['owner' ],
77+ pr_number = config ["pull_request_number" ],
78+ )
79+
80+ # Wait for the cancel operations to complete.
81+ for future in concurrent .futures .as_completed ([cxl_batch_future , cxl_checkrun_future ]):
82+ try :
83+ future .result ()
84+ except Exception as e :
85+ if future is cxl_batch_future :
86+ non_blocking_errors .append (f"Error cancelling prior batch jobs: { e } " )
87+ else :
88+ non_blocking_errors .append (f"Error cancelling prior check runs: { e } " )
89+ return non_blocking_errors
90+
91+
5492def prepare_and_launch_ci_test (
5593 infra_config ,
5694 config ,
5795 bundle_repo_path ,
58- target_repo_path ,
5996):
6097 """The main function that will be called to prepare and launch the CI test.
6198
@@ -68,7 +105,6 @@ def prepare_and_launch_ci_test(
68105 config: The GitHub action environment configuration including
69106 PR metadata and passed config variables.
70107 bundle_repo_path: The path to the bundle repository.
71- target_repo_path: The path to the target repository.
72108
73109 Returns:
74110 A 2-tuple of lists of strings representing errors:
@@ -205,35 +241,11 @@ def prepare_and_launch_ci_test(
205241 else :
206242 chosen_build_environments = [test_select ]
207243
208- # Use a thread pool to cancel prior unfinished jobs and their associated check runs.
209- # This process is done in parallel to save time on slow network-bound operations.
210- with concurrent .futures .ThreadPoolExecutor (max_workers = 2 ) as executor :
211-
212- # Submit operation: cancel prior unfinished AWS Batch jobs for the PR.
213- cxl_batch_future = executor .submit (
214- aws_client .cancel_prior_batch_jobs ,
215- job_queue = infra_config ['batch_queue' ],
216- repo_name = config ['repo_name' ],
217- pr = config ["pull_request_number" ],
218- )
219-
220- # Submit operation: cancel unfinished check runs for the PR.
221- cxl_checkrun_future = executor .submit (
222- github_client .cancel_prior_unfinished_check_runs ,
223- repo = config ['repo_name' ],
224- owner = config ['owner' ],
225- pr_number = config ["pull_request_number" ],
226- )
227-
228- # Wait for the cancel operations to complete.
229- for future in concurrent .futures .as_completed ([cxl_batch_future , cxl_checkrun_future ]):
230- try :
231- future .result ()
232- except Exception as e :
233- if future is cxl_batch_future :
234- non_blocking_errors .append (f"Error cancelling prior batch jobs: { e } " )
235- else :
236- non_blocking_errors .append (f"Error cancelling prior check runs: { e } " )
244+ non_blocking_errors = cancel_prior_jobs_and_check_runs (
245+ non_blocking_errors ,
246+ infra_config ,
247+ config ,
248+ )
237249
238250 # This is a constructor for the configuration needed to submit AWS Batch jobs.
239251 # This constructor reads configuration from the environment and must be
0 commit comments