156 lines
4.8 KiB
Plaintext
156 lines
4.8 KiB
Plaintext
|
|
# Simple Workflow Example
|
||
|
|
# Demonstrates basic workflow creation with sequential operations
|
||
|
|
|
||
|
|
import ..main
|
||
|
|
|
||
|
|
# Simple web application deployment workflow
|
||
|
|
web_app_deployment: main.BatchWorkflow = main.BatchWorkflow {
|
||
|
|
workflow_id: "webapp_deploy_001"
|
||
|
|
name: "Web Application Deployment"
|
||
|
|
description: "Deploy a simple web application with database backend"
|
||
|
|
|
||
|
|
operations: [
|
||
|
|
# Step 1: Create database server
|
||
|
|
main.BatchOperation {
|
||
|
|
operation_id: "create_database"
|
||
|
|
name: "Create Database Server"
|
||
|
|
operation_type: "server"
|
||
|
|
provider: "upcloud"
|
||
|
|
action: "create"
|
||
|
|
parameters: {
|
||
|
|
"hostname": "webapp-db"
|
||
|
|
"plan": "1xCPU-2GB"
|
||
|
|
"zone": "fi-hel2"
|
||
|
|
"server_type": "database"
|
||
|
|
}
|
||
|
|
priority: 10
|
||
|
|
timeout: 600 # 10 minutes
|
||
|
|
}
|
||
|
|
|
||
|
|
# Step 2: Create web servers (can run in parallel)
|
||
|
|
main.BatchOperation {
|
||
|
|
operation_id: "create_web_servers"
|
||
|
|
name: "Create Web Servers"
|
||
|
|
operation_type: "server"
|
||
|
|
provider: "upcloud"
|
||
|
|
action: "create"
|
||
|
|
parameters: {
|
||
|
|
"server_count": "2"
|
||
|
|
"hostname_prefix": "webapp-web"
|
||
|
|
"plan": "1xCPU-1GB"
|
||
|
|
"zone": "fi-hel2"
|
||
|
|
"server_type": "web"
|
||
|
|
}
|
||
|
|
priority: 10
|
||
|
|
timeout: 600
|
||
|
|
allow_parallel: True
|
||
|
|
}
|
||
|
|
|
||
|
|
# Step 3: Install database after database server is ready
|
||
|
|
main.BatchOperation {
|
||
|
|
operation_id: "install_database"
|
||
|
|
name: "Install PostgreSQL"
|
||
|
|
operation_type: "taskserv"
|
||
|
|
action: "create"
|
||
|
|
parameters: {
|
||
|
|
"taskserv": "postgresql"
|
||
|
|
"version": "15"
|
||
|
|
"target_servers": "webapp-db"
|
||
|
|
}
|
||
|
|
dependencies: [
|
||
|
|
main.DependencyDef {
|
||
|
|
target_operation_id: "create_database"
|
||
|
|
dependency_type: "sequential"
|
||
|
|
timeout: 300
|
||
|
|
}
|
||
|
|
]
|
||
|
|
priority: 8
|
||
|
|
timeout: 900 # 15 minutes for database installation
|
||
|
|
}
|
||
|
|
|
||
|
|
# Step 4: Install web stack after web servers are ready
|
||
|
|
main.BatchOperation {
|
||
|
|
operation_id: "install_web_stack"
|
||
|
|
name: "Install Web Stack"
|
||
|
|
operation_type: "taskserv"
|
||
|
|
action: "create"
|
||
|
|
parameters: {
|
||
|
|
"taskserv": "nginx"
|
||
|
|
"target_servers": "webapp-web-*"
|
||
|
|
"config_template": "reverse_proxy"
|
||
|
|
}
|
||
|
|
dependencies: [
|
||
|
|
main.DependencyDef {
|
||
|
|
target_operation_id: "create_web_servers"
|
||
|
|
dependency_type: "sequential"
|
||
|
|
timeout: 300
|
||
|
|
}
|
||
|
|
]
|
||
|
|
priority: 8
|
||
|
|
timeout: 600
|
||
|
|
}
|
||
|
|
|
||
|
|
# Step 5: Configure application after all components are ready
|
||
|
|
main.BatchOperation {
|
||
|
|
operation_id: "configure_application"
|
||
|
|
name: "Configure Web Application"
|
||
|
|
operation_type: "custom"
|
||
|
|
action: "configure"
|
||
|
|
parameters: {
|
||
|
|
"config_type": "application"
|
||
|
|
"database_url": "postgres://webapp-db:5432/webapp"
|
||
|
|
"web_servers": "webapp-web-01,webapp-web-02"
|
||
|
|
}
|
||
|
|
dependencies: [
|
||
|
|
main.DependencyDef {
|
||
|
|
target_operation_id: "install_database"
|
||
|
|
dependency_type: "sequential"
|
||
|
|
timeout: 60
|
||
|
|
},
|
||
|
|
main.DependencyDef {
|
||
|
|
target_operation_id: "install_web_stack"
|
||
|
|
dependency_type: "sequential"
|
||
|
|
timeout: 60
|
||
|
|
}
|
||
|
|
]
|
||
|
|
priority: 5
|
||
|
|
timeout: 300
|
||
|
|
}
|
||
|
|
]
|
||
|
|
|
||
|
|
# Workflow settings
|
||
|
|
max_parallel_operations: 3
|
||
|
|
global_timeout: 3600 # 1 hour total
|
||
|
|
fail_fast: True # Stop on first failure
|
||
|
|
|
||
|
|
# Simple filesystem storage for this example
|
||
|
|
storage: main.StorageConfig {
|
||
|
|
backend: "filesystem"
|
||
|
|
base_path: "./webapp_deployments"
|
||
|
|
enable_persistence: True
|
||
|
|
retention_hours: 168 # 1 week
|
||
|
|
}
|
||
|
|
|
||
|
|
# Basic monitoring
|
||
|
|
monitoring: main.MonitoringConfig {
|
||
|
|
enabled: True
|
||
|
|
backend: "prometheus"
|
||
|
|
enable_tracing: False # Simplified for example
|
||
|
|
log_level: "info"
|
||
|
|
}
|
||
|
|
|
||
|
|
# Conservative retry policy
|
||
|
|
default_retry_policy: main.RetryPolicy {
|
||
|
|
max_attempts: 2
|
||
|
|
initial_delay: 30
|
||
|
|
backoff_multiplier: 2
|
||
|
|
retry_on_errors: ["timeout", "connection_error"]
|
||
|
|
}
|
||
|
|
|
||
|
|
# Enable rollback for safety
|
||
|
|
default_rollback_strategy: main.RollbackStrategy {
|
||
|
|
enabled: True
|
||
|
|
strategy: "immediate"
|
||
|
|
preserve_partial_state: False
|
||
|
|
}
|
||
|
|
}
|