Skip to content

Commit fc78c5e

Browse files
committed
feat: add ALT_DAGS_DIR config for additional DAG search directory
1 parent 5394d09 commit fc78c5e

File tree

6 files changed

+22
-1
lines changed

6 files changed

+22
-1
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: 10 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"),
@@ -547,6 +549,14 @@ paths:
547549
assert.Equal(t, "/custom/data/agent/sessions", cfg.Paths.SessionsDir)
548550
}
549551

552+
func TestLoad_AltDAGsDir_FromYAML(t *testing.T) {
553+
cfg := loadFromYAML(t, `
554+
paths:
555+
altDagsDir: "/custom/alt-dags"
556+
`)
557+
assert.Equal(t, "/custom/alt-dags", cfg.Paths.AltDAGsDir)
558+
}
559+
550560
func TestLoad_EdgeCases_Errors(t *testing.T) {
551561
t.Run("InvalidTimezone", func(t *testing.T) {
552562
err := loadWithErrorFromYAML(t, `tz: "Invalid/Timezone"`)

0 commit comments

Comments
 (0)