The Supervisor class is a core component of the Axion framework, designed to manage and monitor system processes and services in a distributed environment. It acts as a central controller for running background tasks, implementing a robust dispatcher/worker pattern. Its primary responsibilities include:
The class inherits from ObjData.ObjData, giving it direct access to database communication methods.
dispatcher process reads tasks and distributes them to one or more worker processes via a message queue (ObjMessageQueue).webhook), a corresponding database table named stage_<service> (e.g., stage_webhook) holds the records of tasks to be processed. The dispatcher queries this table to find new work.ObjMessageQueue, which is backed by MongoDB, to provide a resilient and scalable buffer between the dispatcher and the workers.acquire_lock method ensures that for any given service, only one dispatcher process can be active, preventing task duplication.__init__(self, DB=0, Id="")Initializes a new Supervisor instance.
DB (Database Connection, optional): An active database connection object. Defaults to 0.Id (str, optional): An identifier for the instance.ObjData.ObjMessageQueue instance for message handling.These methods form the core of the task processing engine.
run_service(self, service: str, role="", guid="")The main entry point for starting a service. It checks if the service is marked as active in the database, performs initial setup, and then calls launch_service (a method assumed to be in a subclass or mixed in) to start the actual processes.
service (str): The name of the service to run (e.g., "webhook", "email").role (str, optional): The role to launch, typically "dispatcher" or "worker".guid (str, optional): A specific GUID to process, if applicable.base_service(self, role="dispatcher", name="")Sets up and runs the main process loop for either a dispatcher or a worker.
role (str): The role of this process. If it contains "dispatcher" or is empty, it starts the dispatcher_process. Otherwise, it starts a worker_process.name (str, optional): A specific name for the worker instance.dispatcher_process(self, sleep_time=1)The main loop for the dispatcher. It continuously performs the following actions:
stage_ table for new tasks.queue.load().rich.progress visual to show pending and dispatched task counts.special_purpose_process hook for non-standard tasks.worker_process(self, name: str, sleep_time=1)The main loop for a worker. It continuously performs the following actions:
queue.pop_list().self.run_direct(context).dispatcher_direct(self, context: str, queue: str, payload: dict)A utility method to push a single, well-formed task directly onto a specified queue.
acquire_lock(self, context: str = "", iteration=1)Attempts to acquire an exclusive, non-blocking file lock for a given context. This is used to ensure only one dispatcher instance is running.
None.release_lock(locked_file_descriptor)Releases a previously acquired file lock.
reconnect_check(self)Pings the database to check if the connection is alive. If the ping fails, it attempts to re-establish the connection.
get_system_load(self)Gathers and returns key performance metrics for the host machine.
(system_name, cpu_load, memory_load, disk_load).Status(self)Runs the supervisorctl status command, parses its output, and updates the def_supervisor database table with the current status of all managed services.
These methods provide a way to introspect the project's "factory" directories and generate documentation automatically.
scan_factory(self, service: str, factory: str = "")Orchestrates the scanning process. It calls factory_list to discover classes and build_mermaid to generate a class diagram, then injects the diagram into the appropriate source file.
factory_list(self, base_dir)Recursively traverses a directory (e.g., factory.core) and inspects Python files to find class definitions.
build_mermaid(self, l: list, parent)Takes the hierarchical list from factory_list and generates a string containing a class diagram in MermaidJS format.
The script can be run from the command line using typer.
preflight()Creates a Supervisor instance and runs a check_preflight method (not defined in this file, likely inherited or in a subclass).
factory(service: str, factory: str = "")Creates a Supervisor instance and calls scan_factory to generate and embed a MermaidJS class diagram for the specified service.
python ObjSupervisor.py factory --service <service_name>
cythonize -3 -a -i ObjSupervisor.py
Compiling /home/axion/projects/axion/factory.core/ObjSupervisor.py because it changed..[1/1] Cythonizing /home/axion/projects/axion/factory.core/ObjSupervisor.py
Updated : 2025-09-10