-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbasic_usage.py
More file actions
64 lines (48 loc) · 2.13 KB
/
basic_usage.py
File metadata and controls
64 lines (48 loc) · 2.13 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
"""Basic usage example for VERONICA Core - Deterministic demo (always succeeds)."""
from veronica_core import VeronicaIntegration
def main():
"""Demonstrate VERONICA Core basics with deterministic flow."""
print("=== VERONICA Core Basic Usage Demo ===\n")
# Initialize with defaults
veronica = VeronicaIntegration(
cooldown_fails=3, # Cooldown after 3 consecutive fails
cooldown_seconds=60, # 1 minute cooldown (reduced for demo)
auto_save_interval=10 # Auto-save every 10 operations
)
# Scenario 1: Successful operations (no cooldown)
print("--- Scenario 1: Successful Operations ---")
task_a = "api_call_users"
for i in range(3):
print(f"Attempt {i+1}: Calling API...")
# Simulate successful API call
veronica.record_pass(task_a)
print(f" Success! (Fail count reset)")
print(f"Cooldown status: {veronica.is_in_cooldown(task_a)}") # False
# Scenario 2: Trigger cooldown (3 consecutive fails)
print("\n--- Scenario 2: Circuit Breaker Activation ---")
task_b = "flaky_service"
for i in range(3):
print(f"Attempt {i+1}: Calling flaky service...")
cooldown_activated = veronica.record_fail(task_b)
fail_count = veronica.get_fail_count(task_b)
print(f" Failed! (Fail count: {fail_count})")
if cooldown_activated:
print(f" >>> Circuit breaker ACTIVATED for {task_b}")
# Verify cooldown
is_cooldown = veronica.is_in_cooldown(task_b)
remaining = veronica.get_cooldown_remaining(task_b)
print(f"\nCooldown active: {is_cooldown}")
print(f"Remaining: {remaining:.0f}s")
# Scenario 3: State persistence
print("\n--- Scenario 3: State Persistence ---")
print("Saving state to disk...")
veronica.save()
# Get statistics
stats = veronica.get_stats()
print(f"\nFinal State: {stats['current_state']}")
print(f"Active Cooldowns: {len(stats['active_cooldowns'])}")
print(f"Fail Counts: {stats['fail_counts']}")
print("\n=== Demo Complete ===")
print("State persisted. Restart will restore cooldowns.")
if __name__ == "__main__":
main()