@@ -162,60 +162,6 @@ def clean_up_pod(
162162 ), f"kubectl clean-up failed with code { result .exit_code } "
163163
164164
165- @task
166- def wait_workload_complete (
167- workload_id : str ,
168- project_id : str ,
169- region : str ,
170- cluster_name : str ,
171- benchmark_steps : int ,
172- override_timeout_in_min : int = 10 ,
173- poke_interval_in_second : int = 60 ,
174- ) -> bool :
175- """
176- Checks for the completion of an workload by repeatedly executing its core logic.
177- The core logic uses workload logs to report the detailed status of successful or failed completion.
178- """
179- # Extract and reuse the logic in the` xpk` module to wait for a workload to be completed.
180- impl = getattr (
181- xpk .wait_for_workload_completion , "python_callable" , None
182- ) or getattr (xpk .wait_for_workload_completion , "__wrapped__" , None )
183-
184- if impl is None :
185- raise AirflowException (
186- f"Cannot extract core callable from { xpk .wait_for_workload_completion } ."
187- "It might not be a valid task/sensor or is wrapped too deeply."
188- )
189-
190- # Dynamically sets the Airflow task timeout based on a custom flag or calculates it using a benchmark step count.
191- if override_timeout_in_min :
192- timeout_in_min = override_timeout_in_min
193- else :
194- max_step_min = 5 # Average time required for each step in lama3-1-405b.
195- timeout_in_min = benchmark_steps * max_step_min
196-
197- timeout_in_sec = timeout_in_min * 60
198-
199- logging .info (
200- f"The timeout for this task is { timeout_in_min } minutes ({ timeout_in_sec } seconds).\n "
201- f"Check if completed every { poke_interval_in_second } seconds."
202- )
203-
204- deadline = datetime .datetime .now () + datetime .timedelta (
205- seconds = timeout_in_sec
206- )
207- while datetime .datetime .now () < deadline :
208- # Call the core function to check if the workload is complete.
209- if impl (workload_id , project_id , region , cluster_name ):
210- return True
211-
212- time .sleep (poke_interval_in_second )
213-
214- raise AirflowException (
215- f"Timed out after { timeout_in_min } min({ timeout_in_sec } s). Please adjust `Override Timeout In Minutes` in UI input."
216- )
217-
218-
219165RECIPE_INSTANCE = recipe_cfg .Recipe .PW_MCJAX_BENCHMARK_RECIPE
220166RECIPE_NAME = RECIPE_INSTANCE .value .lower ()
221167
@@ -247,7 +193,6 @@ def wait_workload_complete(
247193
248194 ### Prerequisites
249195 - This test requires an existing cluster.
250- - This test requires that a dataset with the same name as the UI parameter "[BigQuery Database Dataset]".
251196 - If you're using a service account to pull an image from a different project, you need to grant the service account the `Artifact Registry Reader` role in that project.
252197
253198 ### Procedures
@@ -276,16 +221,13 @@ def wait_workload_complete(
276221 image_full_url = dag_params ["runner" ],
277222 )
278223
279- check_recipe_log = wait_workload_complete .override (
280- task_id = "check_recipe_log " ,
224+ wait_for_workload_complete = xpk . wait_for_workload_completion .override (
225+ task_id = "wait_for_workload_complete " ,
281226 )(
282227 workload_id = derived_params ["workload_id" ],
283228 project_id = dag_params ["project" ],
284229 region = derived_params ["region" ],
285230 cluster_name = dag_params ["cluster_name" ],
286- benchmark_steps = dag_params ["benchmark_steps" ],
287- override_timeout_in_min = dag_params ["override_timeout_in_min" ],
288- poke_interval_in_second = 30 ,
289231 )
290232
291233 clean_up_recipe = xpk .clean_up_workload .override (
@@ -302,7 +244,7 @@ def wait_workload_complete(
302244 >> derived_params
303245 >> commands
304246 >> start_recipe
305- >> check_recipe_log
247+ >> wait_for_workload_complete
306248 >> clean_up_recipe
307249 )
308- start_recipe >> check_recipe_log
250+ start_recipe >> wait_for_workload_complete
0 commit comments