FlexiRule Docs
Advanced Process: Architecture Reference
Runtime orchestration, Registry pattern, and the ProcessOperationExecutor internals.
Advanced Process: Architecture Reference#
Purpose#
The Advanced Process action (internally Process) implements the “Strategy” pattern within FlexiRule. It provides a generic orchestration layer that can execute any registered business operation while providing standardized services like input/output mapping, retry logic, and transactional safety.
Class Structure#
ProcessHandler(ActionHandler)#
- Responsibility: The entry point for all process-type actions.
- Key Method:
execute(action, context, engine) - Orchestration: It does not execute logic directly; instead, it delegates to the
ProcessOperationExecutor.
ProcessOperationExecutor (flexirule/ruleflow/core/process_runtime_v2.py)#
- Responsibility: The high-level runtime for declarative business processes.
- Key Methods:
execute(): Orchestrates the lifecycle of a process operation._resolve_adapter(): Locates the specific Python code (Adapter) for the requested operation._validate_inputs(): Verifies configuration against the operation’s schema.
The Process Registry#
Processes are not hard-coded into the engine. They are discovered dynamically via the ProcessRegistry.
- Discovery: On system startup, the registry scans for all
ProcessDocTypes. - Metadata: Each process defines its available Operations, each with a schema (JSON Schema) for inputs and outputs.
- Binding: Operations are bound to Adapters—Python classes that implement the actual logic.
Execution Lifecycle#
- Context Preparation:
ProcessHandlerhydates the action configuration usingapply_input_mapping. - Executor Initialization: The
ProcessOperationExecutortakes over. - Schema Validation: Inputs are validated. If a required field is missing or of the wrong type, a
ValidationErroris raised. - Savepoint Creation: For synchronous processes, a database savepoint is created.
- Adapter Execution: The specific Adapter’s
execute()method is called. - Result Normalization: The adapter’s return value is normalized according to the output schema.
- Mapping Back: The result is stored in the rule’s
varsbased on thereturn_variableconfiguration.
Async vs. Sync#
- Sync: Runs in the same process/request. If it fails, the rule can rollback the entire transaction.
- Async: Pushed to
frappe.enqueue. The rule continues immediately. Errors in async processes are logged but do not stop the main rule flow.
Extension Points#
Developers can create new processes by:
- Defining a Process DocType: Create the metadata and operations.
- Implementing an Adapter: Create a Python class inheriting from
BaseProcessAdapter. - Registering: Ensure the adapter is linked to the operation in the registry.
Source Files#
- Backend Handler:
flexirule/ruleflow/core/action_handlers/process.py - Runtime Engine:
flexirule/ruleflow/core/process_runtime_v2.py - Registry:
flexirule/ruleflow/core/process_registry.py - Contract:
flexirule/ruleflow/core/contracts.py
Was this page helpful?