Extending the Factory Pattern
Relevant source files
The following files were used as context for generating this wiki page:
The Factory Pattern in flext-target-oracle-wms provides a standardized mechanism for instantiating Oracle WMS targets with varying levels of complexity, from basic configuration to enterprise-grade monitored instances. This pattern abstracts the underlying target initialization logic, ensuring that targets are created with consistent settings, presets, and integration hooks for observability.
Sources: examples/04_factory_usage.py:1-45, src/flext_target_oracle_wms/__init__.py:40-66
Factory Architecture and Components
The factory system is built around two primary classes: FlextTargetFactory for standard target creation and FlextTargetMonitoringFactory for targets requiring integrated observability. These factories utilize structured request models to ensure type safety and configuration integrity.
Target Creation Workflow
The following diagram illustrates the data flow from a configuration request to the instantiation of a functional Oracle WMS target.
Key Components
| Component | Description |
|---|---|
FlextTargetFactory | The core factory class responsible for mapping requests to target instances using configuration dictionaries or request models. |
FlextTargetMonitoringFactory | An extended factory that wraps targets with observability monitors for production tracking. |
TargetCreationRequest | A data model containing base_url, username, password, and optional environment or preset settings. |
MonitoredTargetCreationRequest | Extends the standard request with monitor_name for observability registration. |
Sources: tests/unit/test_oracle_wms_factory.py:18-50, src/flext_target_oracle_wms/__init__.py:40-42
Factory Methods and Usage Patterns
The factory supports multiple entry points depending on whether the source data is a raw dictionary, a typed model, or a set of positional arguments for quick instantiation.
Standard Factory Usage
The FlextTargetFactory supports create_target for model-based instantiation and create_from_config_dict for direct dictionary mapping.
# Model-based creation
request = FlextTargetOracleWmsModels.TargetOracleWms.TargetCreationRequest(
base_url="https://wms.example.oraclecloud.com",
username="wms_user",
password="wms_pass"
)
result = FlextTargetFactory.create_target(request)
Sources: examples/04_factory_usage.py:44-53, tests/unit/test_oracle_wms_factory.py:101-110
Environment Presets
The factory maintains internal presets for different operational environments to simplify configuration:
- development: Default environment for local testing.
- testing: Optimized for CI/CD and unit testing.
- production: Configured with enterprise-grade security and performance defaults.
Sources: tests/unit/test_oracle_wms_factory.py:59-63
Monitored Target Extensions
The FlextTargetMonitoringFactory integrates with flext-observability to provide mission-critical monitoring. It allows for the creation of targets that automatically report metrics and health status.
Configuration and Performance
Factory-created targets follow production-grade performance standards. The factory ensures that the SingerTargetOracleWMS is initialized with appropriate batch sizes and timeouts.
Default Performance Constraints
Based on system benchmarks, the factory-initiated components adhere to the following performance thresholds:
| Operation | Target Performance | Iterations |
|---|---|---|
| Target Creation | < 1.0s (Total) | 1000 |
| Configuration Mapping | < 0.5s | 1000 |
| Monitor Injection | Minimal Overhead | N/A |
Sources: tests/unit/test_benchmarks.py:81-105, examples/README.md:162-170
Advanced Configuration Mapping
The factory supports passing additional_config which allows for enterprise features such as:
- Audit Trails: Enabling comprehensive activity tracking.
- Bulk Insert Mode: Optimizing for high-performance data loading.
- Custom Type Mappings: Overriding standard Singer-to-Oracle type conversions.
Sources: tests/unit/test_oracle_wms_factory.py:92-100, examples/README.md:65-80
Conclusion
Extending the Factory Pattern in the flext-target-oracle-wms project ensures that target lifecycle management is decoupled from business logic. By utilizing FlextTargetFactory and its monitoring counterparts, developers can reliably instantiate targets that are both performance-optimized and production-ready, supporting diverse environments through a unified configuration interface.
Sources: examples/README.md:200-210, tests/unit/test_oracle_wms_factory.py:1-15