Coverage for llm_dataset_engine/orchestration/execution_strategy.py: 80%

1"""

2 Execution strategy abstraction for different execution modes.

3

4 Implements Strategy pattern to support sync, async, and streaming execution

5 without modifying core pipeline logic.

6"""

7

8 from abc import ABC, abstractmethod

9 from typing import AsyncIterator, Iterator, List, Union

10

11 import pandas as pd

12

13 from llm_dataset_engine.core.models import ExecutionResult

14 from llm_dataset_engine.orchestration.execution_context import ExecutionContext

15 from llm_dataset_engine.stages.pipeline_stage import PipelineStage

16

17

18 class ExecutionStrategy(ABC):

19 """

20 Abstract base for execution strategies.

21

22 Follows Strategy pattern: defines interface for executing pipeline stages

23 in different modes (sync, async, streaming).

24 """

25

26 @abstractmethod

27 def execute(

28 self,

29 stages: List[PipelineStage],

30 context: ExecutionContext,

31 ) -> Union[ExecutionResult, Iterator[pd.DataFrame], AsyncIterator[pd.DataFrame]]:

32 """

33 Execute pipeline stages.

34

35 Args:

36 stages: List of pipeline stages to execute

37 context: Execution context for state management

38

39 Returns:

40 ExecutionResult or iterator for streaming

41 """

42 pass

43

44 @abstractmethod

45 def supports_async(self) -> bool:

46 """Whether this strategy supports async execution."""

47 pass

48

49 @abstractmethod

50 def supports_streaming(self) -> bool:

51 """Whether this strategy supports streaming."""

52 pass

53

54 @property

55 @abstractmethod

56 def name(self) -> str:

57 """Strategy name for logging."""

58 pass

59