Instance Lifecycle
Tutorial
Instance Lifecycle
Understand TTL, health checks, and instance states
What You'll Learn
- Lifecycle States - pending → running → terminated
- TTL Management - Automatic and manual termination
- Health Monitoring - Liveness and readiness probes
- Progress Tracking - Monitor long-running operations
# Cell 1 — ParametersUSERNAME = "_FILL_ME_IN_" # Set your email before running# Cell 2 — Connectfrom graph_olap import GraphOLAPClientclient = GraphOLAPClient(username=USERNAME)
# Cell 3 — Provisionfrom notebook_setup import provisionpersonas, conn = provision(USERNAME)analyst = personas["analyst"]admin = personas["admin"]ops = personas["ops"]client = analyst
mapping = client.mappings.list(search="tutorial-customer-graph").items[0]print(f"Connected to: {client._config.api_url}")print(f"Using mapping: {mapping.name} (id={mapping.id})")
1
Instance States
Lifecycle state machine
from graph_olap_schemas import WrapperType
# Instance state transitions# ┌─────────┐ ┌──────────┐ ┌─────────┐ ┌────────────┐# │ pending │───>│ starting │───>│ running │───>│ terminated │# └─────────┘ └──────────┘ └─────────┘ └────────────┘# │# v# ┌──────────┐# │ stopping │# └──────────┘
# Create an instance and observe its initial stateinstance = client.instances.create_and_wait( mapping_id=mapping.id, name="lifecycle-demo", wrapper_type=WrapperType.RYUGRAPH, timeout=300, ttl="PT4H", # 4-hour time-to-live)
# Check the current stateprint(f"Instance ID: {instance.id}")print(f"Status: {instance.status}")print(f"Wrapper: {instance.wrapper_type}")print(f"Expires at: {instance.expires_at}")
2
TTL and Termination
Automatic cleanup
3
Health Checks
Monitoring instance health
# Health checks — two flavours:
# 1. Detailed health info (returns dict with status details)health = client.instances.get_health(instance.id)print("Detailed health:")for key, value in health.items(): print(f" {key}: {value}")
# 2. Quick boolean checkis_healthy = client.instances.check_health(instance.id)print(f"\nHealthy? {is_healthy}")
4
Progress Events
Track operation progress
# Progress tracking for long-running operations# (create_and_wait handles polling internally, but you can also# check progress manually during instance creation)
progress = client.instances.get_progress(instance.id)print(f"Phase: {progress.phase}")print(f"Progress: {progress.progress_percent}%")print(f"Steps: {progress.steps}")Key Takeaways
- Instances transition: pending → starting → running → stopping → terminated
- Use
create_and_wait()with attl(ISO 8601 duration) to auto-terminate extend_ttl(id, hours=N)postpones automatic terminationget_health()returns detailed status;check_health()returns a booleanget_progress()provides phase, progress_percent, and steps for long operations
# Cleanup: terminate the lifecycle-demo instancetry: client.instances.terminate(instance.id) print(f"Terminated instance {instance.id}")except Exception as e: print(f"Instance cleanup: {e}")