2025-10-07 10:32:04 +01:00
|
|
|
use std
|
|
|
|
|
use ../lib_provisioning *
|
2025-12-11 21:57:05 +00:00
|
|
|
use ../lib_provisioning/platform *
|
2025-10-07 10:32:04 +01:00
|
|
|
|
|
|
|
|
# Taskserv workflow definitions
|
2025-12-11 21:57:05 +00:00
|
|
|
|
|
|
|
|
# Get orchestrator endpoint from platform configuration or use provided default
|
|
|
|
|
def get-orchestrator-url [--orchestrator: string = ""]: nothing -> string {
|
|
|
|
|
if ($orchestrator | is-not-empty) {
|
|
|
|
|
return $orchestrator
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
# Try to get from platform discovery
|
|
|
|
|
try {
|
|
|
|
|
service-endpoint "orchestrator"
|
|
|
|
|
} catch {
|
|
|
|
|
# Fallback to default if no active workspace
|
|
|
|
|
"http://localhost:9090"
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
# Detect if orchestrator URL is local (for plugin usage)
|
|
|
|
|
def use-local-plugin [orchestrator_url: string]: nothing -> bool {
|
|
|
|
|
# Check if it's a local endpoint
|
|
|
|
|
(detect-platform-mode $orchestrator_url) == "local"
|
|
|
|
|
}
|
2025-10-07 10:32:04 +01:00
|
|
|
export def taskserv_workflow [
|
|
|
|
|
taskserv: string # Taskserv name
|
|
|
|
|
operation: string # Operation: create, delete, generate, check-updates
|
|
|
|
|
infra?: string # Infrastructure target
|
|
|
|
|
settings?: string # Settings file path
|
|
|
|
|
--check (-c) # Check mode only
|
|
|
|
|
--wait (-w) # Wait for completion
|
2025-12-11 21:57:05 +00:00
|
|
|
--orchestrator: string = "" # Orchestrator URL (optional, uses platform config if not provided)
|
2025-10-07 10:32:04 +01:00
|
|
|
]: nothing -> record {
|
2025-12-11 21:57:05 +00:00
|
|
|
let orch_url = (get-orchestrator-url --orchestrator=$orchestrator)
|
2025-10-07 10:32:04 +01:00
|
|
|
let workflow_data = {
|
|
|
|
|
taskserv: $taskserv,
|
|
|
|
|
operation: $operation,
|
|
|
|
|
infra: ($infra | default ""),
|
|
|
|
|
settings: ($settings | default ""),
|
|
|
|
|
check_mode: $check,
|
|
|
|
|
wait: $wait
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
# Submit to orchestrator
|
2025-12-11 21:57:05 +00:00
|
|
|
let response = (http post $"($orch_url)/workflows/taskserv/create" --content-type "application/json" ($workflow_data | to json))
|
2025-10-07 10:32:04 +01:00
|
|
|
|
|
|
|
|
if not ($response | get success) {
|
|
|
|
|
return { status: "error", message: ($response | get error) }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
let task_id = ($response | get data)
|
|
|
|
|
_print $"Taskserv ($operation) workflow submitted: ($task_id)"
|
|
|
|
|
|
|
|
|
|
if $wait {
|
2025-12-11 21:57:05 +00:00
|
|
|
wait_for_workflow_completion $orch_url $task_id
|
2025-10-07 10:32:04 +01:00
|
|
|
} else {
|
|
|
|
|
{ status: "submitted", task_id: $task_id }
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
# Specific taskserv operations
|
|
|
|
|
export def "taskserv create" [
|
|
|
|
|
taskserv: string # Taskserv name
|
|
|
|
|
infra?: string # Infrastructure target
|
|
|
|
|
settings?: string # Settings file path
|
|
|
|
|
--check (-c) # Check mode only
|
|
|
|
|
--wait (-w) # Wait for completion
|
2025-12-11 21:57:05 +00:00
|
|
|
--orchestrator: string = "" # Orchestrator URL (optional, uses platform config if not provided)
|
2025-10-07 10:32:04 +01:00
|
|
|
]: nothing -> record {
|
|
|
|
|
taskserv_workflow $taskserv "create" $infra $settings --check=$check --wait=$wait --orchestrator $orchestrator
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export def "taskserv delete" [
|
|
|
|
|
taskserv: string # Taskserv name
|
|
|
|
|
infra?: string # Infrastructure target
|
|
|
|
|
settings?: string # Settings file path
|
|
|
|
|
--check (-c) # Check mode only
|
|
|
|
|
--wait (-w) # Wait for completion
|
2025-12-11 21:57:05 +00:00
|
|
|
--orchestrator: string = "" # Orchestrator URL (optional, uses platform config if not provided)
|
2025-10-07 10:32:04 +01:00
|
|
|
]: nothing -> record {
|
|
|
|
|
taskserv_workflow $taskserv "delete" $infra $settings --check=$check --wait=$wait --orchestrator $orchestrator
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export def "taskserv generate" [
|
|
|
|
|
taskserv: string # Taskserv name
|
|
|
|
|
infra?: string # Infrastructure target
|
|
|
|
|
settings?: string # Settings file path
|
|
|
|
|
--check (-c) # Check mode only
|
|
|
|
|
--wait (-w) # Wait for completion
|
2025-12-11 21:57:05 +00:00
|
|
|
--orchestrator: string = "" # Orchestrator URL (optional, uses platform config if not provided)
|
2025-10-07 10:32:04 +01:00
|
|
|
]: nothing -> record {
|
|
|
|
|
taskserv_workflow $taskserv "generate" $infra $settings --check=$check --wait=$wait --orchestrator $orchestrator
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export def "taskserv check-updates" [
|
|
|
|
|
taskserv?: string # Taskserv name (optional for all)
|
|
|
|
|
infra?: string # Infrastructure target
|
|
|
|
|
settings?: string # Settings file path
|
|
|
|
|
--check (-c) # Check mode only
|
|
|
|
|
--wait (-w) # Wait for completion
|
2025-12-11 21:57:05 +00:00
|
|
|
--orchestrator: string = "" # Orchestrator URL (optional, uses platform config if not provided)
|
2025-10-07 10:32:04 +01:00
|
|
|
]: nothing -> record {
|
|
|
|
|
let taskserv_name = ($taskserv | default "")
|
|
|
|
|
taskserv_workflow $taskserv_name "check-updates" $infra $settings --check=$check --wait=$wait --orchestrator $orchestrator
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
def wait_for_workflow_completion [orchestrator: string, task_id: string]: nothing -> record {
|
|
|
|
|
_print "Waiting for workflow completion..."
|
|
|
|
|
|
|
|
|
|
mut result = { status: "pending" }
|
|
|
|
|
|
|
|
|
|
while true {
|
|
|
|
|
let status_response = (http get $"($orchestrator)/tasks/($task_id)")
|
|
|
|
|
|
|
|
|
|
if not ($status_response | get success) {
|
|
|
|
|
return { status: "error", message: "Failed to get task status" }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
let task = ($status_response | get data)
|
|
|
|
|
let task_status = ($task | get status)
|
|
|
|
|
|
|
|
|
|
match $task_status {
|
|
|
|
|
"Completed" => {
|
|
|
|
|
_print $"✅ Workflow completed successfully"
|
|
|
|
|
if ($task | get output | is-not-empty) {
|
|
|
|
|
_print "Output:"
|
|
|
|
|
_print ($task | get output)
|
|
|
|
|
}
|
|
|
|
|
$result = { status: "completed", task: $task }
|
|
|
|
|
break
|
|
|
|
|
},
|
|
|
|
|
"Failed" => {
|
|
|
|
|
_print $"❌ Workflow failed"
|
|
|
|
|
if ($task | get error | is-not-empty) {
|
|
|
|
|
_print "Error:"
|
|
|
|
|
_print ($task | get error)
|
|
|
|
|
}
|
|
|
|
|
$result = { status: "failed", task: $task }
|
|
|
|
|
break
|
|
|
|
|
},
|
|
|
|
|
"Running" => {
|
|
|
|
|
_print $"🔄 Workflow is running..."
|
|
|
|
|
},
|
|
|
|
|
_ => {
|
|
|
|
|
_print $"⏳ Workflow status: ($task_status)"
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
sleep 2sec
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return $result
|
|
|
|
|
}
|