Skip to content

Commit 228e4ae

Browse files
sahalbelamyottahmd
andauthored
ingest yaml with filename (#1630)
Co-authored-by: Yota Hamada <yohamta@gmail.com>
1 parent 5394d09 commit 228e4ae

File tree

7 files changed

+23
-10
lines changed

7 files changed

+23
-10
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -289,6 +289,7 @@ Full documentation is available at [docs.daguit.dev](https://docs.daguit.dev/).
289289
|---------------------|---------|-------------|
290290
| `DAGU_HOME` | - | Base directory that overrides all path configurations |
291291
| `DAGU_DAGS_DIR` | `~/.config/dagu/dags` | Directory for DAG definitions |
292+
| `DAGU_ALT_DAGS_DIR` | - | Additional directory to search for DAG definitions |
292293
| `DAGU_LOG_DIR` | `~/.local/share/dagu/logs` | Directory for log files |
293294
| `DAGU_DATA_DIR` | `~/.local/share/dagu/data` | Directory for application data |
294295
| `DAGU_SUSPEND_FLAGS_DIR` | `~/.local/share/dagu/suspend` | Directory for suspend flags |

internal/cmd/context.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -377,10 +377,16 @@ type dagStoreConfig struct {
377377

378378
// dagStore returns a new DAGRepository instance.
379379
func (c *Context) dagStore(cfg dagStoreConfig) (exec.DAGStore, error) {
380+
// Merge configured alternate DAGs directory into search paths if provided
381+
searchPaths := append([]string{}, cfg.SearchPaths...)
382+
if c.Config != nil && c.Config.Paths.AltDAGsDir != "" {
383+
searchPaths = append(searchPaths, c.Config.Paths.AltDAGsDir)
384+
}
385+
380386
store := filedag.New(
381387
c.Config.Paths.DAGsDir,
382388
filedag.WithFlagsBaseDir(c.Config.Paths.SuspendFlagsDir),
383-
filedag.WithSearchPaths(cfg.SearchPaths),
389+
filedag.WithSearchPaths(searchPaths),
384390
filedag.WithFileCache(cfg.Cache),
385391
filedag.WithSkipExamples(c.Config.Core.SkipExamples),
386392
filedag.WithSkipDirectoryCreation(cfg.SkipDirectoryCreation),

internal/cmn/config/config.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -250,6 +250,7 @@ type PathsConfig struct {
250250
SuspendFlagsDir string
251251
AdminLogsDir string
252252
BaseConfig string
253+
AltDAGsDir string
253254
DAGRunsDir string
254255
QueueDir string
255256
ProcDir string

internal/cmn/config/definition.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,7 @@ type PathsDef struct {
181181
SuspendFlagsDir string `mapstructure:"suspendFlagsDir"`
182182
AdminLogsDir string `mapstructure:"adminLogsDir"`
183183
BaseConfig string `mapstructure:"baseConfig"`
184+
AltDagsDir string `mapstructure:"altDagsDir"`
184185
DAGRunsDir string `mapstructure:"dagRunsDir"`
185186
QueueDir string `mapstructure:"queueDir"`
186187
ProcDir string `mapstructure:"procDir"`

internal/cmn/config/loader.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -312,6 +312,7 @@ func (l *ConfigLoader) loadPathsConfig(cfg *Config, def Definition) error {
312312
source string
313313
}{
314314
{"DAGsDir", &cfg.Paths.DAGsDir, def.Paths.DAGsDir},
315+
{"AltDAGsDir", &cfg.Paths.AltDAGsDir, def.Paths.AltDagsDir},
315316
{"SuspendFlagsDir", &cfg.Paths.SuspendFlagsDir, def.Paths.SuspendFlagsDir},
316317
{"DataDir", &cfg.Paths.DataDir, def.Paths.DataDir},
317318
{"LogDir", &cfg.Paths.LogDir, def.Paths.LogDir},
@@ -1250,6 +1251,7 @@ var envBindings = []envBinding{
12501251
// Paths
12511252
{key: "paths.dagsDir", env: "DAGS", isPath: true},
12521253
{key: "paths.dagsDir", env: "DAGS_DIR", isPath: true},
1254+
{key: "paths.altDagsDir", env: "ALT_DAGS_DIR", isPath: true},
12531255
{key: "paths.executable", env: "EXECUTABLE", isPath: true},
12541256
{key: "paths.logDir", env: "LOG_DIR", isPath: true},
12551257
{key: "paths.dataDir", env: "DATA_DIR", isPath: true},

internal/cmn/config/loader_test.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ func TestLoad_Env(t *testing.T) {
6868
"DAGU_PROC_DIR": filepath.Join(testPaths, "proc"),
6969
"DAGU_QUEUE_DIR": filepath.Join(testPaths, "queue"),
7070
"DAGU_SERVICE_REGISTRY_DIR": filepath.Join(testPaths, "service-registry"),
71+
"DAGU_ALT_DAGS_DIR": filepath.Join(testPaths, "alt-dags"),
7172

7273
"DAGU_LATEST_STATUS_TODAY": "true",
7374

@@ -168,6 +169,7 @@ func TestLoad_Env(t *testing.T) {
168169
},
169170
Paths: PathsConfig{
170171
DAGsDir: filepath.Join(testPaths, "dags"),
172+
AltDAGsDir: filepath.Join(testPaths, "alt-dags"),
171173
Executable: filepath.Join(testPaths, "bin", "dagu"),
172174
LogDir: filepath.Join(testPaths, "logs"),
173175
DataDir: filepath.Join(testPaths, "data"),

internal/persis/filedag/store.go

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -81,15 +81,15 @@ func New(baseDir string, opts ...Option) exec.DAGStore {
8181
if options.FlagsBaseDir == "" {
8282
options.FlagsBaseDir = filepath.Join(baseDir, "flags")
8383
}
84-
uniqSearchPaths := make(map[string]struct{})
85-
uniqSearchPaths[baseDir] = struct{}{}
86-
uniqSearchPaths["."] = struct{}{}
87-
for _, path := range options.SearchPaths {
88-
uniqSearchPaths[path] = struct{}{}
89-
}
90-
searchPaths := make([]string, 0, len(uniqSearchPaths))
91-
for path := range uniqSearchPaths {
92-
searchPaths = append(searchPaths, path)
84+
// Build search paths in deterministic order: baseDir first, then ".", then additional paths.
85+
seen := make(map[string]struct{})
86+
var searchPaths []string
87+
for _, p := range append([]string{baseDir, "."}, options.SearchPaths...) {
88+
if _, ok := seen[p]; ok {
89+
continue
90+
}
91+
seen[p] = struct{}{}
92+
searchPaths = append(searchPaths, p)
9393
}
9494

9595
return &Storage{

0 commit comments

Comments
 (0)