feat: add DAG core functions — parse, validate, topo sort, resolve env, cron match (0007a, 0007d)

Pure functions for parsing dagu-compatible YAML, validating DAG structure,
topological sorting with parallel levels (Kahn's algorithm), and env variable
resolution. Also adds cron_match for schedule matching.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-04-12 13:05:05 +02:00
parent d98f517598
commit 3136eb862f
21 changed files with 1569 additions and 0 deletions
+20
View File
@@ -0,0 +1,20 @@
---
name: dag_continue_on
lang: go
domain: core
version: "1.0.0"
algebraic: product
definition: |
type DagContinueOn struct {
Failure bool
Skipped bool
}
description: "Politica de continuacion de un step DAG ante fallos o saltos. Cuando Failure=true el DAG no se detiene si el step falla. Cuando Skipped=true tampoco se detiene si el step es saltado."
tags: [dag, workflow, policy, error-handling]
uses_types: []
file_path: "functions/core/dag_definition.go"
---
## Notas
Tipo producto. Embebido en DagStep. Corresponde al campo `continue_on` del YAML de Dagu.
+31
View File
@@ -0,0 +1,31 @@
---
name: dag_definition
lang: go
domain: core
version: "1.0.0"
algebraic: product
definition: |
type DagDefinition struct {
Name string
Description string
Group string
Type string
WorkingDir string
Shell string
Env map[string]string
Schedule []string
Steps []DagStep
HandlerOn DagHandlers
Tags []string
TimeoutSec int
FilePath string
}
description: "Definicion completa de un workflow DAG parseada desde YAML compatible con Dagu. Contiene steps, handlers de ciclo de vida, variables de entorno, schedule y metadatos del flujo."
tags: [dag, workflow, yaml, dagu, definition]
uses_types: [dag_step_go_core, dag_handlers_go_core]
file_path: "functions/core/dag_definition.go"
---
## Notas
Tipo producto. Type puede ser "graph" (ejecucion paralela por niveles topologicos) o vacio (cadena secuencial). Schedule es siempre una lista de strings (normalizado desde string o lista en el YAML). FilePath se rellena opcionalmente por el caller para saber el origen del archivo.
+22
View File
@@ -0,0 +1,22 @@
---
name: dag_handlers
lang: go
domain: core
version: "1.0.0"
algebraic: product
definition: |
type DagHandlers struct {
Init []DagStep
Success []DagStep
Failure []DagStep
Exit []DagStep
}
description: "Handlers de ciclo de vida de un DAG. Cada campo contiene steps que se ejecutan en el evento correspondiente: inicializacion, exito, fallo o salida (siempre). Corresponde a handler_on o handlers en el YAML de Dagu."
tags: [dag, workflow, handlers, lifecycle]
uses_types: [dag_step_go_core]
file_path: "functions/core/dag_definition.go"
---
## Notas
Tipo producto. Embebido en DagDefinition. Los campos handler_on y handlers son aliases en el YAML de Dagu — ambos se normalizan a este tipo. Cada handler puede ser un step unico o una lista de steps en el YAML.
+20
View File
@@ -0,0 +1,20 @@
---
name: dag_retry_policy
lang: go
domain: core
version: "1.0.0"
algebraic: product
definition: |
type DagRetryPolicy struct {
Limit int
IntervalSec int
}
description: "Politica de reintentos automaticos para un step DAG. Limit es el numero maximo de reintentos e IntervalSec es el tiempo de espera entre intentos en segundos."
tags: [dag, workflow, retry, policy]
uses_types: []
file_path: "functions/core/dag_definition.go"
---
## Notas
Tipo producto. Embebido en DagStep. Corresponde al campo `retry_policy` del YAML de Dagu. Limit=0 significa sin reintentos.
+33
View File
@@ -0,0 +1,33 @@
---
name: dag_step
lang: go
domain: core
version: "1.0.0"
algebraic: product
definition: |
type DagStep struct {
Name string
ID string
Description string
Command string
Script string
Args []string
Shell string
Dir string
Depends []string
Env map[string]string
ContinueOn DagContinueOn
RetryPolicy DagRetryPolicy
TimeoutSec int
Output string
Tags []string
}
description: "Un paso individual en un workflow DAG con command/script, dependencias y configuracion de reintentos. Soporta variables de entorno por step, directorio de trabajo propio y politica continue_on."
tags: [dag, workflow, step, yaml, dagu]
uses_types: [dag_continue_on_go_core, dag_retry_policy_go_core]
file_path: "functions/core/dag_definition.go"
---
## Notas
Tipo producto. El campo ID es opcional y se usa como referencia en otros steps (ej: `${id.stdout}`). Si Name e ID estan ambos vacios, el step es invalido. Env del step se mergea sobre el Env del DAG padre durante la resolucion.
+22
View File
@@ -0,0 +1,22 @@
---
name: dag_validation_result
lang: go
domain: core
version: "1.0.0"
algebraic: product
definition: |
type DagValidationResult struct {
Valid bool
Errors []string
Warnings []string
Levels [][]string
}
description: "Resultado de validar un DagDefinition. Contiene errores estructurales (ciclos, depends invalidos, nombres duplicados), warnings (command+script simultaneos) y los niveles topologicos calculados si el DAG es valido."
tags: [dag, validation, workflow, result]
uses_types: []
file_path: "functions/core/dag_definition.go"
---
## Notas
Tipo producto. Levels solo se rellena cuando Valid=true. Cada sub-slice de Levels contiene los nombres/IDs de steps que pueden ejecutarse en paralelo. El orden de Levels refleja el orden topologico del grafo de dependencias.