Files
osmedeus/internal/executor/workflow_state.go
T
j3ssie f5840272c5 feat: add run cancellation, event enhancements, and performance optimizations
Major features:
- Add run registry for tracking active runs with PID management
- Add API-based run cancellation with process termination
- Add event trigger input vars syntax for multi-variable extraction
- Add filter_functions with utility function support in triggers
- Add event envelope injection for full event context in workflows
- Add write coordinator for batched database operations

API improvements:
- Add logout endpoint and diffs endpoints for assets/vulnerabilities
- Add step-results listing endpoint
- Update schedule model with target, workspace, params fields
- Change run_id to run_uuid across API responses

Performance:
- Add compiled JS program caching for 60-80% faster loop conditions
- Add parallel shard rendering for 20-40% faster workflow startup
- Add memory-mapped I/O for large file line counting
- Add efficient output buffer combining in runners
- Add mtime-based cache invalidation for workflow loader

Other changes:
- Rename trigger field from trigger to triggers in workflow YAML
- Disable pongo2 HTML autoescape for shell command templates
- Update JWT expiration default to 1440 minutes (1 day)
- Change CORS default to reflect-origin for credentials support
- Add source_type field to events (run, eval, api)
- Skip copying core Unix tools to external-binaries
2026-01-24 01:11:33 +08:00

66 lines
1.7 KiB
Go

package executor
import (
"fmt"
"os"
"path/filepath"
"github.com/goccy/go-yaml"
"github.com/j3ssie/osmedeus/v5/internal/core"
)
// ExportWorkflowState writes the workflow YAML to the state file
func ExportWorkflowState(stateFile string, workflow *core.Workflow) error {
if stateFile == "" {
return fmt.Errorf("state file path is empty")
}
// Ensure directory exists
dir := filepath.Dir(stateFile)
if err := os.MkdirAll(dir, 0755); err != nil {
return fmt.Errorf("failed to create directory: %w", err)
}
// Marshal workflow to YAML
data, err := yaml.Marshal(workflow)
if err != nil {
return fmt.Errorf("failed to marshal workflow: %w", err)
}
// Write to file
if err := os.WriteFile(stateFile, data, 0644); err != nil {
return fmt.Errorf("failed to write workflow state file: %w", err)
}
return nil
}
// ExportModuleWorkflowState writes a module workflow YAML to the modules folder
func ExportModuleWorkflowState(folder string, moduleName string, workflow *core.Workflow) error {
if folder == "" || moduleName == "" {
return fmt.Errorf("folder or module name is empty")
}
// Ensure directory exists
if err := os.MkdirAll(folder, 0755); err != nil {
return fmt.Errorf("failed to create directory: %w", err)
}
// Build filename: run-{module-name}.yaml
filename := fmt.Sprintf("run-%s.yaml", moduleName)
filePath := filepath.Join(folder, filename)
// Marshal workflow to YAML
data, err := yaml.Marshal(workflow)
if err != nil {
return fmt.Errorf("failed to marshal workflow: %w", err)
}
// Write to file
if err := os.WriteFile(filePath, data, 0644); err != nil {
return fmt.Errorf("failed to write module workflow state file: %w", err)
}
return nil
}