1313# permissions and limitations under the License.
1414"""Base orchestrator class."""
1515
16- import time
1716from abc import ABC , abstractmethod
1817from typing import (
1918 TYPE_CHECKING ,
4039 HookExecutionException ,
4140 IllegalOperationError ,
4241 RunMonitoringError ,
43- RunStoppedException ,
4442)
4543from zenml .hooks .hook_validators import load_and_run_hook
4644from zenml .logger import get_logger
5048 publish_pipeline_run_status_update ,
5149 publish_schedule_metadata ,
5250)
53- from zenml .orchestrators .step_launcher import StepLauncher
5451from zenml .orchestrators .utils import get_config_environment_vars
5552from zenml .stack import Flavor , Stack , StackComponent , StackComponentConfig
5653from zenml .steps .step_context import RunContext , get_or_create_run_context
@@ -274,16 +271,6 @@ def run(
274271 # in the orchestrator environment
275272 base_environment .update (secrets )
276273
277- is_dynamic = True
278- if is_dynamic :
279- submission_result = self .submit_dynamic_pipeline (
280- snapshot = snapshot ,
281- stack = stack ,
282- environment = base_environment ,
283- placeholder_run = placeholder_run ,
284- )
285- return
286-
287274 prevent_client_side_caching = handle_bool_env_var (
288275 ENV_ZENML_PREVENT_CLIENT_SIDE_CACHING , default = False
289276 )
@@ -292,6 +279,7 @@ def run(
292279 placeholder_run
293280 and self .config .supports_client_side_caching
294281 and not snapshot .schedule
282+ and not snapshot .is_dynamic
295283 and not prevent_client_side_caching
296284 ):
297285 from zenml .orchestrators import cache_utils
@@ -310,22 +298,10 @@ def run(
310298 else :
311299 logger .debug ("Skipping client-side caching." )
312300
313- step_environments = {}
314- for invocation_id , step in snapshot .step_configurations .items ():
315- from zenml .utils .env_utils import get_step_environment
316-
317- step_environment = get_step_environment (
318- step_config = step .config ,
319- stack = stack ,
320- )
321-
322- combined_environment = base_environment .copy ()
323- combined_environment .update (step_environment )
324- step_environments [invocation_id ] = combined_environment
325-
326301 try :
327302 if (
328- getattr (self .submit_pipeline , "__func__" , None )
303+ not snapshot .is_dynamic
304+ and getattr (self .submit_pipeline , "__func__" , None )
329305 is BaseOrchestrator .submit_pipeline
330306 ):
331307 logger .warning (
@@ -357,13 +333,37 @@ def run(
357333 f"run metadata: { e } "
358334 )
359335 else :
360- submission_result = self .submit_pipeline (
361- snapshot = snapshot ,
362- stack = stack ,
363- base_environment = base_environment ,
364- step_environments = step_environments ,
365- placeholder_run = placeholder_run ,
366- )
336+ if snapshot .is_dynamic :
337+ submission_result = self .submit_dynamic_pipeline (
338+ snapshot = snapshot ,
339+ stack = stack ,
340+ environment = base_environment ,
341+ placeholder_run = placeholder_run ,
342+ )
343+ else :
344+ step_environments = {}
345+ for (
346+ invocation_id ,
347+ step ,
348+ ) in snapshot .step_configurations .items ():
349+ from zenml .utils .env_utils import get_step_environment
350+
351+ step_environment = get_step_environment (
352+ step_config = step .config ,
353+ stack = stack ,
354+ )
355+
356+ combined_environment = base_environment .copy ()
357+ combined_environment .update (step_environment )
358+ step_environments [invocation_id ] = combined_environment
359+
360+ submission_result = self .submit_pipeline (
361+ snapshot = snapshot ,
362+ stack = stack ,
363+ base_environment = base_environment ,
364+ step_environments = step_environments ,
365+ placeholder_run = placeholder_run ,
366+ )
367367 if placeholder_run :
368368 publish_pipeline_run_status_update (
369369 pipeline_run_id = placeholder_run .id ,
@@ -427,54 +427,14 @@ def run_step(
427427 RunStoppedException: If the run was stopped.
428428 BaseException: If the step failed all retries.
429429 """
430+ from zenml .pipelines .dynamic .runner import _run_step_sync
430431
431- def _launch_step () -> None :
432- assert self ._active_snapshot
433-
434- launcher = StepLauncher (
435- snapshot = self ._active_snapshot ,
436- step = step ,
437- orchestrator_run_id = self .get_orchestrator_run_id (),
438- )
439- launcher .launch ()
440-
441- if self .config .handles_step_retries :
442- _launch_step ()
443- else :
444- # The orchestrator subclass doesn't handle step retries, so we
445- # handle it in-process instead
446- retries = 0
447- retry_config = step .config .retry
448- max_retries = retry_config .max_retries if retry_config else 0
449- delay = retry_config .delay if retry_config else 0
450- backoff = retry_config .backoff if retry_config else 1
451-
452- while retries <= max_retries :
453- try :
454- _launch_step ()
455- except RunStoppedException :
456- # Don't retry if the run was stopped
457- raise
458- except BaseException :
459- retries += 1
460- if retries <= max_retries :
461- logger .info (
462- "Sleeping for %d seconds before retrying step `%s`." ,
463- delay ,
464- step .config .name ,
465- )
466- time .sleep (delay )
467- delay *= backoff
468- else :
469- if max_retries > 0 :
470- logger .error (
471- "Failed to run step `%s` after %d retries." ,
472- step .config .name ,
473- max_retries ,
474- )
475- raise
476- else :
477- break
432+ _run_step_sync (
433+ snapshot = self ._active_snapshot ,
434+ step = step ,
435+ orchestrator_run_id = self .get_orchestrator_run_id (),
436+ retry = not self .config .handles_step_retries ,
437+ )
478438
479439 @property
480440 def supports_dynamic_pipelines (self ) -> bool :
0 commit comments