Skip to content

Instance Lifecycle

Tutorial

Instance Lifecycle

Understand TTL, health checks, and instance states

30 min Advanced
InstanceLifecycleTTLHealth

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 — Parameters
USERNAME = "_FILL_ME_IN_" # Set your email before running
# Cell 2 — Connect
from graph_olap import GraphOLAPClient
client = GraphOLAPClient(username=USERNAME)
# Cell 3 — Provision
from notebook_setup import provision
personas, 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 state
instance = 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 state
print(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 check
is_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 a ttl (ISO 8601 duration) to auto-terminate
  • extend_ttl(id, hours=N) postpones automatic termination
  • get_health() returns detailed status; check_health() returns a boolean
  • get_progress() provides phase, progress_percent, and steps for long operations
# Cleanup: terminate the lifecycle-demo instance
try:
client.instances.terminate(instance.id)
print(f"Terminated instance {instance.id}")
except Exception as e:
print(f"Instance cleanup: {e}")