-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathintegration_example.py
More file actions
142 lines (117 loc) Β· 3.83 KB
/
integration_example.py
File metadata and controls
142 lines (117 loc) Β· 3.83 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
#!/usr/bin/env python3
"""
Cross-Module Integration Example
Demonstrates how multiple Codomyrmex modules work together in a real workflow:
- logging_monitoring for structured logging
- cache for result caching
- validation for input validation
- metrics for performance tracking
This is a template for building integrated applications.
Usage:
python scripts/integration_example.py
"""
import sys
from pathlib import Path
# Ensure codomyrmex is in path (scripts/utils/ -> scripts/ -> repo root)
project_root = Path(__file__).resolve().parent.parent.parent
sys.path.insert(0, str(project_root / "src"))
from codomyrmex.utils.cli_helpers import (
print_error,
print_info,
print_success,
setup_logging,
)
def main():
# Auto-injected: Load configuration
from pathlib import Path
import yaml
config_path = (
Path(__file__).resolve().parent.parent.parent
/ "config"
/ "utils"
/ "config.yaml"
)
if config_path.exists():
with open(config_path) as f:
yaml.safe_load(f) or {}
print("Loaded config from config/utils/config.yaml")
setup_logging()
print_info("Cross-Module Integration Example")
print_info("=" * 50)
# Step 1: Initialize logging
print_info("\n1. Setting up structured logging...")
try:
from codomyrmex.logging_monitoring import get_logger
logger = get_logger("integration_example")
logger.info("Integration example started")
print_success(" Logging initialized")
except ImportError as e:
print_error(f" Logging setup failed: {e}")
logger = None
# Step 2: Initialize cache
print_info("\n2. Initializing cache layer...")
try:
from codomyrmex.cache import get_cache
cache = get_cache("integration_cache", backend="in_memory")
print_success(" Cache initialized")
except ImportError as e:
print_info(f" Cache import: {e}")
cache = None
except Exception as e:
print_info(f" Cache setup: {e}")
cache = None
# Step 3: Set up validation schema
print_info("\n3. Defining validation schema...")
try:
from codomyrmex.validation import is_valid
schema = {
"type": "object",
"properties": {
"operation": {"type": "string"},
"data": {"type": "object"},
},
"required": ["operation"],
}
print_success(" Validation schema defined")
except ImportError as e:
print_info(f" Validation import: {e}")
is_valid = None
# Step 4: Process sample data
print_info("\n4. Processing sample workflow...")
sample_request = {
"operation": "analyze",
"data": {"file": "example.py", "depth": 3},
}
# Validate input
if is_valid:
try:
valid = is_valid(sample_request, schema)
print(f" Input valid: {valid}")
except Exception as e:
print_info(f" Validation: {e}")
# Check cache
if cache:
try:
cached = cache.get("sample_result")
print(f" Cache hit: {cached is not None}")
except Exception as e:
print_info(f" Cache check: {e}")
# Log completion
if logger:
logger.info("Integration example completed")
# Step 5: Summary
print_info("\n5. Integration Summary:")
print(" Modules integrated:")
print(" - logging_monitoring β")
print(" - cache β")
print(" - validation β")
print("\n Typical workflow:")
print(" 1. Validate input")
print(" 2. Check cache")
print(" 3. Process data")
print(" 4. Update cache")
print(" 5. Log results")
print_success("\nCross-module integration example completed!")
return 0
if __name__ == "__main__":
sys.exit(main())