Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,7 @@ Full documentation is available at [docs.dagu.cloud](https://docs.dagu.cloud/).
|---------------------|---------|-------------|
| `DAGU_HOME` | - | Base directory that overrides all path configurations |
| `DAGU_DAGS_DIR` | `~/.config/dagu/dags` | Directory for DAG definitions |
| `DAGU_ALT_DAGS_DIR` | - | Additional directory to search for DAG definitions |
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add default path

~/.config/dagu/alt_dags

| `DAGU_LOG_DIR` | `~/.local/share/dagu/logs` | Directory for log files |
| `DAGU_DATA_DIR` | `~/.local/share/dagu/data` | Directory for application data |
| `DAGU_SUSPEND_FLAGS_DIR` | `~/.local/share/dagu/suspend` | Directory for suspend flags |
Expand Down
269 changes: 140 additions & 129 deletions api/v2/api.gen.go

Large diffs are not rendered by default.

8 changes: 6 additions & 2 deletions api/v2/api.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1613,8 +1613,12 @@ paths:
queue:
type: string
description: "Override the queue to use for this DAG-run"
required:
- spec
filename:
type: string
description: "Filename for the yaml file"
oneOf:
- required: [spec]
- required: [filename]
responses:
"200":
description: "DAG-run successfully enqueued"
Expand Down
8 changes: 7 additions & 1 deletion internal/cmd/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -375,10 +375,16 @@ type dagStoreConfig struct {

// dagStore returns a new DAGRepository instance.
func (c *Context) dagStore(cfg dagStoreConfig) (exec.DAGStore, error) {
// Merge configured alternate DAGs directory into search paths if provided
searchPaths := append([]string{}, cfg.SearchPaths...)
if c.Config != nil && c.Config.Paths.AltDAGsDir != "" {
searchPaths = append(searchPaths, c.Config.Paths.AltDAGsDir)
}

store := filedag.New(
c.Config.Paths.DAGsDir,
filedag.WithFlagsBaseDir(c.Config.Paths.SuspendFlagsDir),
filedag.WithSearchPaths(cfg.SearchPaths),
filedag.WithSearchPaths(searchPaths),
filedag.WithFileCache(cfg.Cache),
filedag.WithSkipExamples(c.Config.Core.SkipExamples),
filedag.WithSkipDirectoryCreation(cfg.SkipDirectoryCreation),
Expand Down
1 change: 1 addition & 0 deletions internal/cmn/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,7 @@ type PathsConfig struct {
SuspendFlagsDir string
AdminLogsDir string
BaseConfig string
AltDAGsDir string
DAGRunsDir string
QueueDir string
ProcDir string
Expand Down
1 change: 1 addition & 0 deletions internal/cmn/config/definition.go
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,7 @@ type PathsDef struct {
SuspendFlagsDir string `mapstructure:"suspendFlagsDir"`
AdminLogsDir string `mapstructure:"adminLogsDir"`
BaseConfig string `mapstructure:"baseConfig"`
AltDagsDir string `mapstructure:"altDagsDir"`
DAGRunsDir string `mapstructure:"dagRunsDir"`
QueueDir string `mapstructure:"queueDir"`
ProcDir string `mapstructure:"procDir"`
Expand Down
1 change: 1 addition & 0 deletions internal/cmn/config/loader.go
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,7 @@ func (l *ConfigLoader) loadPathsConfig(cfg *Config, def Definition) error {
source string
}{
{"DAGsDir", &cfg.Paths.DAGsDir, def.Paths.DAGsDir},
{"AltDAGsDir", &cfg.Paths.AltDAGsDir, def.Paths.AltDagsDir},
{"SuspendFlagsDir", &cfg.Paths.SuspendFlagsDir, def.Paths.SuspendFlagsDir},
{"DataDir", &cfg.Paths.DataDir, def.Paths.DataDir},
{"LogDir", &cfg.Paths.LogDir, def.Paths.LogDir},
Expand Down
56 changes: 52 additions & 4 deletions internal/service/frontend/api/v2/dagruns.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,15 +149,22 @@ func (a *API) EnqueueDAGRunFromSpec(ctx context.Context, request api.EnqueueDAGR
return nil, err
}

if request.Body == nil || request.Body.Spec == "" {
if request.Body == nil {
return nil, &Error{
HTTPStatus: http.StatusBadRequest,
Code: api.ErrorCodeBadRequest,
Message: "spec is required",
Message: "no body was given",
}
}

var dagRunId, params string
if request.Body.Spec == nil && request.Body.Filename == nil || request.Body.Spec != nil && request.Body.Filename != nil {
return nil, &Error{
HTTPStatus: http.StatusBadRequest,
Code: api.ErrorCodeBadRequest,
Message: "either give spec or url; don't give both",
}
}
var dagRunId, params, filename string
if request.Body.DagRunId != nil {
dagRunId = *request.Body.DagRunId
}
Expand All @@ -171,8 +178,49 @@ func (a *API) EnqueueDAGRunFromSpec(ctx context.Context, request api.EnqueueDAGR
if request.Body.Params != nil {
params = *request.Body.Params
}
if request.Body.Filename != nil {
filename = *request.Body.Filename
}
var finalSpec string
if strings.HasSuffix(filename, ".yaml") || strings.HasSuffix(filename, ".yml") {
// Use configured alternate DAGs directory if provided
if a.config != nil && a.config.Paths.AltDAGsDir != "" {
filename = fmt.Sprintf("%s/%s", a.config.Paths.AltDAGsDir, filepath.Base(filename))
} else {
return nil, &Error{
HTTPStatus: http.StatusBadRequest,
Code: api.ErrorCodeBadRequest,
Message: "Make sure ALT_DAGS_DIR is set in the config file",
}
}
const maxSpecBytes = 1 << 20 // 1 MiB (tune or reuse config)
info, err := os.Stat(filename)
if err != nil {
return nil, fmt.Errorf("error stating file: %w", err)
}
if info.Size() > maxSpecBytes {
return nil, &Error{
HTTPStatus: http.StatusBadRequest,
Code: api.ErrorCodeBadRequest,
Message: "spec file too large",
}
}
data, err := os.ReadFile(filename) //nolint:gosec
if err != nil {
return nil, fmt.Errorf("Error reading file: %w", err)
}
finalSpec = string(data)
} else if request.Body.Spec != nil {
finalSpec = *request.Body.Spec
} else {
return nil, &Error{
HTTPStatus: http.StatusBadRequest,
Code: api.ErrorCodeBadRequest,
Message: "Make sure file is a yaml file",
}
}

dag, cleanup, err := a.loadInlineDAG(ctx, request.Body.Spec, request.Body.Name, dagRunId)
dag, cleanup, err := a.loadInlineDAG(ctx, finalSpec, request.Body.Name, dagRunId)
if err != nil {
return nil, err
}
Expand Down
2 changes: 1 addition & 1 deletion internal/service/frontend/api/v2/dags_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ steps:
name := "inline_enqueue_spec"

resp := server.Client().Post("/api/v2/dag-runs/enqueue", api.EnqueueDAGRunFromSpecJSONRequestBody{
Spec: spec,
Spec: &spec,
Name: &name,
}).
ExpectStatus(http.StatusOK).
Expand Down