This document provides a guide for developers on how to create new services within the Axion framework using the ObjServiceReference.py template. The reference service demonstrates the standard structure, methods, and attributes that all Axion services should implement to ensure consistency and compatibility with the workflow engine.
Adhering to a standard structure ensures that:
ObjServiceReference.py)A standard service file consists of three main parts:
ObjServiceApi Class: The core of the service where all logic is encapsulated.typer command-line interface for standalone testing.ObjServiceApi ClassThis is the main class that must inherit from ObjApi.ObjApi.
__init__(self, DB=0)The constructor initializes the service.
super().__init__(DB): Must be called to initialize the base class.self._IsA (str): A unique, human-readable name for the service (e.g., "MyAwesomeService").self.ServiceCode (str): A short, unique code (often uppercase) used to look up the service's configuration in def_service (e.g., "MYAWSOME").self.DefTable (str): The database table for service definitions, almost always "def_service".self.Param1 to self.Param9):
None.self._Status (str): Initialize to "STARTED". The workflow engine uses this to track the service's state.self.Result1 (str): Initialize to "". Used for a high-level result status (e.g., "SUCCESS", "ERROR").self.Result2 (str): Initialize to "". Used for a detailed result message or data payload.Connect(self)This method handles the setup and validation phase of the service.
True on success and False on failure. If it returns False, the Send() method will not be called.self._Status, self.Result1, and self.Result2 to appropriate error values before returning False.Send(self)This is where the core logic of the service resides.
Connect() returns True.try...except block. In the except block, log the error and set the status attributes (_Status, Result1, Result2) accordingly.self._Status to "DONE", self.Result1 to "SUCCESS", and self.Result2 to a meaningful success message.run_workflow_direct(self, param1, param2, ...)This is the standard entry point for the Axion workflow engine.
param1, param2, etc., to self.Param1, self.Param2.self.Connect().Connect() was successful, call self.Send().self.Result2.The if __name__ == '__main__': block allows the service to be run from the command line for development and testing.
typer to define commands and arguments.run command:
service = ObjServiceApi().run_workflow_direct() method, passing in the CLI arguments.service.note() to print the results (Result1, Result2) to the console.ObjServiceReference.py and rename it to ObjService<YourServiceName>.py.__init__:
_IsA to <YourServiceName>.ServiceCode to a short code (e.g., YOUTUBE).Param1, Param2, etc. for.Connect: Write the logic to validate your specific parameters.Send: Write your core service logic inside the try...except block.run (CLI command):
typer.Argument and typer.Option definitions to match your parameters, including help text.service.run_workflow_direct() passes the correct arguments.python factory/service/package/core/ObjService<YourServiceName>.py run [ARGUMENTS]