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

20 statements  

« prev     ^ index     » next       coverage.py v7.10.7, created at 2025-10-15 18:04 +0200

1""" 

2Execution strategy abstraction for different execution modes. 

3 

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

5without modifying core pipeline logic. 

6""" 

7 

8from abc import ABC, abstractmethod 

9from typing import AsyncIterator, Iterator, List, Union 

10 

11import pandas as pd 

12 

13from llm_dataset_engine.core.models import ExecutionResult 

14from llm_dataset_engine.orchestration.execution_context import ExecutionContext 

15from llm_dataset_engine.stages.pipeline_stage import PipelineStage 

16 

17 

18class 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