Files
osmedeus/internal/executor/state_export.go
T
j3ssie baac7a016a feat: add worker management, hooks support, and db cleanup enhancements
- Add worker eval command for distributed function execution with Redis hooks registration
- Add worker set command to update worker fields (alias, public-ip, ssh-enabled, ssh-keys-path)
- Enhance worker status with JSON output, search filtering, and column selection (--columns, --exclude-columns, --search)
- Add --keep-setting flag to install base/validate commands to preserve osm-settings.yaml after base installation
- Fix binary installation in Nix: replace CopyInstalledBinaryToFolder with SymlinkInstalledBinaryToFolder
- Add --clean-ws flag to db clean command for removing workspace data
- Add HooksEnabled field to Run records when creating runs from CLI and API
- Add comprehensive test coverage for hook execution (pre/post hooks, execution order, failure handling)
- Add test coverage for worker commands (eval, set, status with JSON) and db clean operations
- Improve usage documentation for worker subcommands and db operations
2026-02-15 10:47:44 +07:00

79 lines
2.1 KiB
Go

package executor
import (
"github.com/j3ssie/osmedeus/v5/internal/core"
"github.com/j3ssie/osmedeus/v5/internal/state"
)
// ExportState exports the current run state to a JSON file
// It uses database data if available, otherwise falls back to in-memory data from result and execCtx
func ExportState(stateFile string, result *core.WorkflowResult, execCtx *core.ExecutionContext) error {
ctx := buildExportContext(result, execCtx)
return state.Export(stateFile, ctx)
}
func buildExportContext(result *core.WorkflowResult, execCtx *core.ExecutionContext) *state.ExportContext {
ctx := &state.ExportContext{}
// Populate from execCtx
if execCtx != nil {
ctx.RunUUID = execCtx.RunUUID
ctx.WorkflowName = execCtx.WorkflowName
ctx.WorkflowKind = string(execCtx.WorkflowKind)
ctx.Target = execCtx.Target
ctx.WorkspacePath = execCtx.WorkspacePath
ctx.WorkspaceName = execCtx.WorkspaceName
ctx.Params = execCtx.Params
// Read hook/run metadata from execution context variables
if v, ok := execCtx.GetVariable("HooksEnabled"); ok {
if b, ok := v.(bool); ok {
ctx.HooksEnabled = b
}
}
if v, ok := execCtx.GetVariable("RunMode"); ok {
if s, ok := v.(string); ok {
ctx.RunMode = s
}
}
if v, ok := execCtx.GetVariable("RunPriority"); ok {
if s, ok := v.(string); ok {
ctx.RunPriority = s
}
}
}
// Populate/override from result
if result != nil {
if ctx.RunUUID == "" {
ctx.RunUUID = result.RunUUID
}
if ctx.WorkflowName == "" {
ctx.WorkflowName = result.WorkflowName
}
ctx.WorkflowKind = string(result.WorkflowKind)
ctx.Target = result.Target
ctx.Status = string(result.Status)
startTime := result.StartTime
endTime := result.EndTime
ctx.StartedAt = &startTime
ctx.CompletedAt = &endTime
ctx.TotalSteps = len(result.Steps)
completedSteps := 0
for _, step := range result.Steps {
if step.Status == core.StepStatusSuccess {
completedSteps++
}
}
ctx.CompletedSteps = completedSteps
if result.Error != nil {
ctx.ErrorMessage = result.Error.Error()
}
ctx.Artifacts = result.Artifacts
}
return ctx
}