Documentation
¶
Overview ¶
Package dagu provides an experimental embedded engine API for running Dagu DAGs from Go applications.
The embedding API is experimental and may change before it is declared stable. It currently supports local file-backed execution and distributed execution against existing Dagu coordinators.
Example ¶
package main
import (
"context"
"log"
"github.com/dagucloud/dagu"
)
func main() {
ctx := context.Background()
engine, err := dagu.New(ctx, dagu.Options{
HomeDir: "/var/lib/myapp/dagu",
})
if err != nil {
log.Fatal(err)
}
defer func() {
if err := engine.Close(context.Background()); err != nil {
log.Fatal(err)
}
}()
run, err := engine.RunYAML(ctx, []byte(`
name: embedded
steps:
- name: hello
command: echo "$MESSAGE"
`), dagu.WithParams(map[string]string{"MESSAGE": "hello"}))
if err != nil {
log.Fatal(err)
}
status, err := run.Wait(ctx)
if err != nil {
log.Fatal(err)
}
_ = status
}
Output:
Example (Distributed) ¶
package main
import (
"context"
"log"
"github.com/dagucloud/dagu"
)
func main() {
ctx := context.Background()
engine, err := dagu.New(ctx, dagu.Options{
HomeDir: "/var/lib/myapp/dagu-worker",
DefaultMode: dagu.ExecutionModeDistributed,
Distributed: &dagu.DistributedOptions{
Coordinators: []string{"127.0.0.1:50055"},
TLS: dagu.TLSOptions{Insecure: true},
WorkerSelector: map[string]string{
"pool": "default",
},
},
})
if err != nil {
log.Fatal(err)
}
defer func() {
if err := engine.Close(context.Background()); err != nil {
log.Fatal(err)
}
}()
worker, err := engine.NewWorker(dagu.WorkerOptions{
Labels: map[string]string{"pool": "default"},
})
if err != nil {
log.Fatal(err)
}
workerCtx, stopWorker := context.WithCancel(ctx)
defer stopWorker()
go func() {
if err := worker.Start(workerCtx); err != nil {
log.Print(err)
}
}()
if err := worker.WaitReady(ctx); err != nil {
log.Fatal(err)
}
run, err := engine.RunFile(ctx, "daily-report.yaml")
if err != nil {
log.Fatal(err)
}
status, err := run.Wait(ctx)
if err != nil {
log.Fatal(err)
}
_ = status
}
Output:
Index ¶
- func RegisterExecutor(name string, factory ExecutorFactory, opts ...ExecutorOption)
- func UnregisterExecutor(name string)
- type DistributedOptions
- type Engine
- func (e *Engine) Close(ctx context.Context) error
- func (e *Engine) NewWorker(opts WorkerOptions) (*Worker, error)
- func (e *Engine) Outputs(ctx context.Context, ref RunRef) (map[string]string, error)
- func (e *Engine) RunFile(ctx context.Context, path string, opts ...RunOption) (*Run, error)
- func (e *Engine) RunYAML(ctx context.Context, yaml []byte, opts ...RunOption) (*Run, error)
- func (e *Engine) Status(ctx context.Context, ref RunRef) (*Status, error)
- func (e *Engine) Stop(ctx context.Context, ref RunRef) error
- type ExecutionMode
- type Executor
- type ExecutorCapabilities
- type ExecutorFactory
- type ExecutorOption
- type Options
- type Run
- func (r *Run) ID() string
- func (r *Run) Name() string
- func (r *Run) Outputs(ctx context.Context) (map[string]string, error)
- func (r *Run) Ref() RunRef
- func (r *Run) Status(ctx context.Context) (*Status, error)
- func (r *Run) Stop(ctx context.Context) error
- func (r *Run) Wait(ctx context.Context) (*Status, error)
- type RunOption
- func WithDefaultWorkingDir(dir string) RunOption
- func WithDryRun(enabled bool) RunOption
- func WithLabels(labels ...string) RunOption
- func WithMode(mode ExecutionMode) RunOption
- func WithName(name string) RunOption
- func WithParams(params map[string]string) RunOption
- func WithParamsList(params []string) RunOption
- func WithRunID(id string) RunOption
- func WithTags(tags ...string) RunOptiondeprecated
- func WithWorkerSelector(selector map[string]string) RunOption
- type RunRef
- type Status
- type Step
- type StepValidator
- type TLSOptions
- type Worker
- type WorkerOptions
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func RegisterExecutor ¶
func RegisterExecutor(name string, factory ExecutorFactory, opts ...ExecutorOption)
RegisterExecutor registers a custom executor type before engine or runtime use. It panics when name is empty, invalid, or factory is nil. Registration mutates global process state and must be completed before concurrent DAG execution.
func UnregisterExecutor ¶
func UnregisterExecutor(name string)
UnregisterExecutor removes a custom executor type registered by RegisterExecutor. It is intended for tests and should not run concurrently with engine use.
Types ¶
type DistributedOptions ¶
type DistributedOptions struct {
// Coordinators are coordinator gRPC addresses.
Coordinators []string
// TLS configures coordinator client TLS.
TLS TLSOptions
// WorkerSelector constrains distributed runs to matching workers.
WorkerSelector map[string]string
// PollInterval controls distributed run status polling.
PollInterval time.Duration
// MaxStatusErrors is the number of consecutive status failures before Wait fails.
MaxStatusErrors int
}
DistributedOptions configures distributed execution.
type Engine ¶
type Engine struct {
// contains filtered or unexported fields
}
Engine is an embedded Dagu engine backed by the configured file stores.
func (*Engine) NewWorker ¶
func (e *Engine) NewWorker(opts WorkerOptions) (*Worker, error)
NewWorker creates an embedded distributed worker.
func (*Engine) RunYAML ¶
RunYAML loads a DAG definition from YAML bytes and starts it asynchronously.
type ExecutionMode ¶
type ExecutionMode string
ExecutionMode controls how a DAG run is dispatched.
const ( // ExecutionModeLocal runs the DAG in the current process. ExecutionModeLocal ExecutionMode = "local" // ExecutionModeDistributed dispatches the DAG to configured coordinators. ExecutionModeDistributed ExecutionMode = "distributed" )
type Executor ¶
type Executor = runtimeexec.Executor
Executor is implemented by custom step executors.
type ExecutorCapabilities ¶
type ExecutorCapabilities = core.ExecutorCapabilities
ExecutorCapabilities declares which step fields a custom executor supports.
type ExecutorFactory ¶
ExecutorFactory creates an Executor for a loaded step.
type ExecutorOption ¶
type ExecutorOption func(*executorRegistration)
ExecutorOption customizes custom executor registration.
func WithExecutorCapabilities ¶
func WithExecutorCapabilities(caps ExecutorCapabilities) ExecutorOption
WithExecutorCapabilities registers supported step fields for the custom executor.
func WithStepValidator ¶
func WithStepValidator(validator StepValidator) ExecutorOption
WithStepValidator registers a validation function for the custom executor.
type Options ¶
type Options struct {
// HomeDir is the Dagu application home used for default config and data paths.
HomeDir string
// ConfigFile loads Dagu configuration from an explicit config file.
ConfigFile string
// DAGsDir overrides the directory used to resolve named DAGs and sub-DAGs.
DAGsDir string
// DataDir overrides the file-backed state directory.
DataDir string
// LogDir overrides the run log directory.
LogDir string
// ArtifactDir overrides the artifact directory.
ArtifactDir string
// BaseConfig points at a base configuration file applied during DAG loading.
BaseConfig string
// Logger receives embedded engine logs. A quiet logger is used when nil.
Logger *slog.Logger
// DefaultMode is used when a run does not set WithMode.
DefaultMode ExecutionMode
// Distributed configures dispatch and worker clients.
Distributed *DistributedOptions
}
Options configures an embedded Dagu engine.
type Run ¶
type Run struct {
// contains filtered or unexported fields
}
Run is a handle for an asynchronous DAG run.
type RunOption ¶
type RunOption func(*runOptions)
RunOption customizes a single DAG run.
func WithDefaultWorkingDir ¶
WithDefaultWorkingDir sets the default working directory while loading a DAG.
func WithDryRun ¶
WithDryRun enables or disables dry-run mode.
func WithMode ¶
func WithMode(mode ExecutionMode) RunOption
WithMode overrides the engine default execution mode.
func WithParams ¶
WithParams sets DAG parameters from a key-value map.
func WithParamsList ¶
WithParamsList sets DAG parameters from Dagu-style KEY=VALUE entries.
func WithWorkerSelector ¶
WithWorkerSelector sets the distributed worker selector for one run.
type Status ¶
type Status struct {
Name string
RunID string
AttemptID string
Status string
StartedAt time.Time
FinishedAt time.Time
Error string
LogFile string
ArchiveDir string
WorkerID string
TriggerType string
}
Status is a stable snapshot of a DAG run.
type StepValidator ¶
type StepValidator = core.StepValidator
StepValidator validates custom executor step configuration during DAG loading.
type TLSOptions ¶
type TLSOptions struct {
// Insecure explicitly allows plaintext coordinator connections.
Insecure bool
// CertFile is the client certificate file for TLS connections.
CertFile string
// KeyFile is the client private key file for TLS connections.
KeyFile string
// ClientCAFile is the CA file used to verify coordinator certificates.
ClientCAFile string
// SkipTLSVerify skips coordinator certificate verification.
SkipTLSVerify bool
}
TLSOptions configures TLS for coordinator and worker peer clients.
type Worker ¶
type Worker struct {
// contains filtered or unexported fields
}
Worker is a distributed worker connected to configured coordinators.
type WorkerOptions ¶
type WorkerOptions struct {
// ID is the worker identifier. A host and process based ID is generated when empty.
ID string
// MaxActiveRuns limits concurrent DAG runs. A default is used when zero or negative.
MaxActiveRuns int
// Labels are advertised to coordinators and matched by worker selectors.
Labels map[string]string
// Coordinators overrides DistributedOptions.Coordinators when non-empty.
// If empty, the worker falls back to the engine-level DistributedOptions.
// The resolved coordinator list must contain at least one non-empty address.
Coordinators []string
// TLS overrides DistributedOptions.TLS when non-zero. If zero, the worker
// falls back to the engine-level DistributedOptions TLS settings.
TLS TLSOptions
// HealthPort starts the worker health endpoint on the given port. Zero disables it.
HealthPort int
}
WorkerOptions configures an embedded distributed worker.
Directories
¶
| Path | Synopsis |
|---|---|
|
api
|
|
|
v1
Package api provides primitives to interact with the openapi HTTP API.
|
Package api provides primitives to interact with the openapi HTTP API. |
|
conformance
|
|
|
examples
|
|
|
embedded/custom-executor
command
|
|
|
embedded/distributed
command
|
|
|
embedded/local
command
|
|
|
internal
|
|
|
cmn/dirlock
Package dirlock provides a directory-based locking mechanism for coordinating access to shared resources across multiple processes.
|
Package dirlock provides a directory-based locking mechanism for coordinating access to shared resources across multiple processes. |
|
cmn/logger/tag
Package tag provides standardized tag functions for structured logging.
|
Package tag provides standardized tag functions for structured logging. |
|
cmn/schema
Package schema provides embedded JSON schemas for use across the codebase.
|
Package schema provides embedded JSON schemas for use across the codebase. |
|
core/spec/types
Package types provides typed union types for YAML fields that accept multiple formats.
|
Package types provides typed union types for YAML fields that accept multiple formats. |
|
dagsettings
Package dagsettings contains server-side DAG settings.
|
Package dagsettings contains server-side DAG settings. |
|
dagstate
Package dagstate defines persistent state shared across DAG runs.
|
Package dagstate defines persistent state shared across DAG runs. |
|
dispatch
Package dispatch holds control-plane policy for deciding how a DAG run is executed.
|
Package dispatch holds control-plane policy for deciding how a DAG run is executed. |
|
llm
Package llm provides a generic abstraction layer for interacting with Large Language Model providers.
|
Package llm provides a generic abstraction layer for interacting with Large Language Model providers. |
|
llm/allproviders
Package allproviders imports all LLM providers to register them.
|
Package allproviders imports all LLM providers to register them. |
|
llm/providers/anthropic
Package anthropic provides an LLM provider implementation for Anthropic's Claude API.
|
Package anthropic provides an LLM provider implementation for Anthropic's Claude API. |
|
llm/providers/gemini
Package gemini provides an LLM provider implementation for Google's Gemini API.
|
Package gemini provides an LLM provider implementation for Google's Gemini API. |
|
llm/providers/local
Package local provides an LLM provider implementation for local OpenAI-compatible servers.
|
Package local provides an LLM provider implementation for local OpenAI-compatible servers. |
|
llm/providers/openai
Package openai provides an LLM provider implementation for OpenAI's API.
|
Package openai provides an LLM provider implementation for OpenAI's API. |
|
llm/providers/openrouter
Package openrouter provides an LLM provider implementation for OpenRouter's API.
|
Package openrouter provides an LLM provider implementation for OpenRouter's API. |
|
llm/providers/zai
Package zai provides an LLM provider implementation for Z.AI's API.
|
Package zai provides an LLM provider implementation for Z.AI's API. |
|
llm/toolschema
Package toolschema derives LLM function-calling parameter schemas from DAG parameter definitions.
|
Package toolschema derives LLM function-calling parameter schemas from DAG parameter definitions. |
|
node
Package node wires runtime node adapters.
|
Package node wires runtime node adapters. |
|
output
Package output provides tree-structured rendering for DAG execution status.
|
Package output provides tree-structured rendering for DAG execution status. |
|
persis
Package persis defines the storage backend interface for Dagu's control plane.
|
Package persis defines the storage backend interface for Dagu's control plane. |
|
persis/file
Package file implements persis.Backend on the local filesystem.
|
Package file implements persis.Backend on the local filesystem. |
|
persis/file/audit
Package audit provides a file-based implementation of the audit Store interface.
|
Package audit provides a file-based implementation of the audit Store interface. |
|
persis/file/eventstore
Package eventstore provides a file-based implementation of the event store.
|
Package eventstore provides a file-based implementation of the event store. |
|
persis/file/tokensecret
Package tokensecret provides a file-based implementation of auth.TokenSecretProvider.
|
Package tokensecret provides a file-based implementation of auth.TokenSecretProvider. |
|
persis/store
Package store consolidates small persistence stores that each wrap a persis.Collection.
|
Package store consolidates small persistence stores that each wrap a persis.Collection. |
|
persis/testutil
Package testutil provides test helpers for the persistence layer.
|
Package testutil provides test helpers for the persistence layer. |
|
profile
Package profile contains runtime profile domain models.
|
Package profile contains runtime profile domain models. |
|
proto/convert
Package convert provides conversion functions between execution types and proto messages.
|
Package convert provides conversion functions between execution types and proto messages. |
|
runtime/builtin/chat
Package chat provides an executor for chat (LLM-based session) steps.
|
Package chat provides an executor for chat (LLM-based session) steps. |
|
runtime/builtin/controller
Package controller registers the executor identity of the synthesized step that drives a controller DAG.
|
Package controller registers the executor identity of the synthesized step that drives a controller DAG. |
|
runtime/builtin/redis
Package redis provides Redis executor capabilities for Dagu workflows.
|
Package redis provides Redis executor capabilities for Dagu workflows. |
|
runtime/builtin/sql
Package sql provides SQL executor capabilities for PostgreSQL and SQLite databases.
|
Package sql provides SQL executor capabilities for PostgreSQL and SQLite databases. |
|
runtime/builtin/sql/drivers/postgres
Package postgres provides the PostgreSQL driver for the SQL executor.
|
Package postgres provides the PostgreSQL driver for the SQL executor. |
|
runtime/builtin/sql/drivers/sqlite
Package sqlite provides the SQLite driver for the SQL executor.
|
Package sqlite provides the SQLite driver for the SQL executor. |
|
runtime/controller
Package controller implements the decision layer of a controller DAG: the catalog of actions offered to the LLM, the goal state it works against, and the planner that turns a conversation into the next action.
|
Package controller implements the decision layer of a controller DAG: the catalog of actions offered to the LLM, the goal state it works against, and the planner that turns a conversation into the next action. |
|
runtime/runstate
Package runstate defines the execution-state port used by the runtime.
|
Package runstate defines the execution-state port used by the runtime. |
|
runtime/runstate/memstore
Package memstore provides an in-memory runtime run-state store.
|
Package memstore provides an in-memory runtime run-state store. |
|
secret
Package secret contains the team secret registry domain model.
|
Package secret contains the team secret registry domain model. |
|
service/audit
Package audit provides a generic audit logging system for tracking user actions.
|
Package audit provides a generic audit logging system for tracking user actions. |
|
service/authmapping
Package authmapping maps external group memberships to Dagu authorization.
|
Package authmapping maps external group memberships to Dagu authorization. |
|
service/frontend/terminal
Package terminal provides a web-based terminal for admin users.
|
Package terminal provides a web-based terminal for admin users. |
|
service/oidcprovision
Package oidcprovision provides OIDC user provisioning functionality for builtin auth mode.
|
Package oidcprovision provides OIDC user provisioning functionality for builtin auth mode. |
|
service/scheduler/filenotify
Package filenotify provides a mechanism for watching file(s) for changes.
|
Package filenotify provides a mechanism for watching file(s) for changes. |
|
service/trustedproxyprovision
Package trustedproxyprovision provisions users through proxy authentication.
|
Package trustedproxyprovision provisions users through proxy authentication. |
|
subflow
Package subflow adapts Dagu child workflow execution to the runtime executor's child workflow interface.
|
Package subflow adapts Dagu child workflow execution to the runtime executor's child workflow interface. |
|
tools/llmsgen/cmd
command
|
|
|
view
Package view defines saved Overview view configurations.
|
Package view defines saved Overview view configurations. |
|
proto
|
|


