1+ """
2+ FSModule module provides the base class for all FunctionStream modules.
3+
4+ This module defines the abstract base class FSModule that all FunctionStream modules
5+ must inherit from. It provides a common interface for module initialization and
6+ data processing, ensuring consistency across different module implementations.
7+ """
8+
19from abc import ABC , abstractmethod
210from typing import Dict , Any
311
@@ -8,32 +16,51 @@ class FSModule(ABC):
816 """
917 Base class for all FunctionStream modules.
1018
11- This class provides a common interface for all modules in the FunctionStream SDK.
12- Each module must implement the process method to handle incoming data.
19+ This abstract base class provides a common interface for all modules in the
20+ FunctionStream SDK. Each module must implement the init and process methods
21+ to handle module initialization and incoming data processing.
1322
1423 Attributes:
15- name (str): The name of the module
24+ name (str): The name of the module (to be set during initialization).
1625 """
1726
1827 @abstractmethod
1928 def init (self , context : FSContext ):
2029 """
21- Initialize the module with a name.
30+ Initialize the module with the provided context.
31+
32+ This method is called during module initialization to set up the module
33+ with the necessary context and configuration. Subclasses must implement
34+ this method to handle any required setup.
2235
2336 Args:
24- name (str): The name of the module
37+ context (FSContext): The context object containing configuration and
38+ runtime information for the module.
2539 """
40+ pass
2641
2742 @abstractmethod
2843 async def process (self , context : FSContext , data : Dict [str , Any ]) -> Dict [str , Any ]:
2944 """
30- Process incoming data.
45+ Process incoming data asynchronously.
46+
47+ This method is the core processing function that handles incoming data.
48+ Subclasses must implement this method to define the specific data processing
49+ logic for their module. The method should be asynchronous to support
50+ non-blocking operations.
3151
3252 Args:
33- context (FSContext): The context object containing configuration and runtime information
34- data (Dict[str, Any]): The input data to process
53+ context (FSContext): The context object containing configuration and
54+ runtime information.
55+ data (Dict[str, Any]): The input data to process. This is typically
56+ a dictionary containing the message payload
57+ and any associated metadata.
3558
3659 Returns:
37- Union[Dict[str, Any], Awaitable[Dict[str, Any]]]: The processed data or an awaitable that will resolve to the processed data
60+ Dict[str, Any]: The processed data that should be returned as the
61+ result of the processing operation.
62+
63+ Raises:
64+ NotImplementedError: This method must be implemented by subclasses.
3865 """
3966 raise NotImplementedError ("Subclasses must implement process method" )
0 commit comments