Skip to content

Commit be528cd

Browse files
authored
Add run and params field (#573)
* rename config variable command -> executable * Add sub workflow feature * Update API for adding 'run' and 'params'
1 parent 3c6772c commit be528cd

File tree

30 files changed

+321
-70
lines changed

30 files changed

+321
-70
lines changed

README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,7 @@ dagu version
255255
- ️[Quick Start Guide](https://dagu.readthedocs.io/en/latest/quickstart.html)
256256
- [Command Line Interface](https://dagu.readthedocs.io/en/latest/cli.html)
257257
- [Web User Interface](https://dagu.readthedocs.io/en/latest/web_interface.html)
258-
- YAML Format
258+
- Writing DAG
259259
- [Minimal DAG Definition](https://dagu.readthedocs.io/en/latest/yaml_format.html#minimal-dag-definition)
260260
- [Running Arbitrary Code Snippets](https://dagu.readthedocs.io/en/latest/yaml_format.html#running-arbitrary-code-snippets)
261261
- [Environment Variables](https://dagu.readthedocs.io/en/latest/yaml_format.html#defining-environment-variables)
@@ -266,6 +266,8 @@ dagu version
266266
- [Redirecting Stdout and Stderr](https://dagu.readthedocs.io/en/latest/yaml_format.html#redirecting-stdout-and-stderr)
267267
- [Lifecycle Hooks](https://dagu.readthedocs.io/en/latest/yaml_format.html#adding-lifecycle-hooks)
268268
- [Repeating Task](https://dagu.readthedocs.io/en/latest/yaml_format.html#repeating-a-task-at-regular-intervals)
269+
- [Minimal DAG Definition](https://dagu.readthedocs.io/en/latest/yaml_format.html#minimal-dag-definition)
270+
- [Running Sub-DAG](https://dagu.readthedocs.io/en/latest/yaml_format.html#running-sub-dag)
269271
- [All Available Fields for a DAG](https://dagu.readthedocs.io/en/latest/yaml_format.html#all-available-fields-for-dags)
270272
- [All Available Fields for a Step](https://dagu.readthedocs.io/en/latest/yaml_format.html#all-available-fields-for-steps)
271273
- Example DAGs

cmd/common_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ func setupTest(t *testing.T) (string, engine.Engine, persistence.DataStoreFactor
3030
DataDir: path.Join(tmpDir, ".dagu", "data"),
3131
})
3232

33-
e := engine.NewFactory(ds, nil).Create()
33+
e := engine.NewFactory(ds, config.Get()).Create()
3434

3535
return tmpDir, e, ds
3636
}

cmd/restart_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ func TestRestartCommand(t *testing.T) {
5555
require.NoError(t, err)
5656

5757
df := client.NewDataStoreFactory(config.Get())
58-
e = engine.NewFactory(df, nil).Create()
58+
e = engine.NewFactory(df, config.Get()).Create()
5959

6060
sts := e.GetRecentHistory(d, 2)
6161
require.Len(t, sts, 2)

cmd/retry.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ func retryCmd() *cobra.Command {
2626

2727
// TODO: use engine.Engine instead of client.DataStoreFactory
2828
df := client.NewDataStoreFactory(config.Get())
29-
e := engine.NewFactory(df, nil).Create()
29+
e := engine.NewFactory(df, config.Get()).Create()
3030

3131
hs := df.NewHistoryStore()
3232

docs/source/yaml_format.rst

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -461,6 +461,19 @@ Formatting JSON
461461
462462
.. _command-execution-over-ssh:
463463

464+
465+
Running Sub-DAG
466+
~~~~~~~~~~~~~~~~
467+
468+
You can run a sub-DAG from a DAG file. The sub-DAG is defined in a separate file and can be called using the `run` field.
469+
470+
.. code-block:: yaml
471+
472+
steps:
473+
- name: A task
474+
run: <DAG file name> # e.g., sub_dag, sub_dag.yaml, /path/to/sub_dag.yaml
475+
params: "FOO=BAR" # optional
476+
464477
All Available Fields
465478
--------------------
466479

@@ -545,6 +558,8 @@ Each step can have its own set of configurations, including:
545558
- ``repeatPolicy``: The repeat policy for the step.
546559
- ``preconditions``: The conditions that must be met before a step can run.
547560
- ``depends``: The step depends on the other step.
561+
- ``run``: The sub-DAG to run.
562+
- ``params``: The parameters to pass to the sub-DAG.
548563

549564
Example:
550565

@@ -576,4 +591,6 @@ Example:
576591
- condition: "`echo $1`"
577592
expected: "param1"
578593
depends:
579-
- some task name step
594+
- some task name step
595+
run: sub_dag
596+
params: "FOO=BAR"

go.mod

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,13 @@ require (
2121
github.com/jessevdk/go-flags v1.5.0
2222
github.com/mattn/go-shellwords v1.0.12
2323
github.com/mitchellh/mapstructure v1.5.0
24+
github.com/pkg/errors v0.9.1
2425
github.com/robfig/cron/v3 v3.0.1
2526
github.com/spf13/cobra v1.6.1
2627
github.com/spf13/viper v1.15.0
2728
github.com/stretchr/testify v1.8.2
2829
go.uber.org/fx v1.20.0
30+
go.uber.org/goleak v1.3.0
2931
golang.org/x/exp v0.0.0-20230817173708-d852ddb80c63
3032
golang.org/x/text v0.12.0
3133
gopkg.in/yaml.v2 v2.4.0
@@ -53,7 +55,6 @@ require (
5355
github.com/opencontainers/go-digest v1.0.0 // indirect
5456
github.com/opencontainers/image-spec v1.0.2 // indirect
5557
github.com/pelletier/go-toml/v2 v2.0.6 // indirect
56-
github.com/pkg/errors v0.9.1 // indirect
5758
github.com/sirupsen/logrus v1.9.0 // indirect
5859
github.com/spf13/afero v1.9.3 // indirect
5960
github.com/spf13/cast v1.5.0 // indirect
@@ -63,7 +64,6 @@ require (
6364
go.mongodb.org/mongo-driver v1.11.3 // indirect
6465
go.uber.org/atomic v1.9.0 // indirect
6566
go.uber.org/dig v1.17.0 // indirect
66-
go.uber.org/goleak v1.3.0 // indirect
6767
go.uber.org/multierr v1.8.0 // indirect
6868
go.uber.org/zap v1.23.0 // indirect
6969
golang.org/x/mod v0.12.0 // indirect

go.sum

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ cloud.google.com/go/storage v1.10.0/go.mod h1:FLPqc6j+Ki4BU591ie1oL6qBQGu2Bl/tZ9
3737
cloud.google.com/go/storage v1.14.0/go.mod h1:GrKmX003DSIwi9o29oFT7YDnHYwZoctc3fOKtUw0Xmo=
3838
dmitri.shuralyov.com/gpu/mtl v0.0.0-20190408044501-666a987793e9/go.mod h1:H6x//7gZCb22OMCxBHrMx7a5I7Hp++hsVxbQ4BYO7hU=
3939
github.com/Azure/go-ansiterm v0.0.0-20210617225240-d185dfc1b5a1 h1:UQHMgLO+TxOElx5B5HZ4hJQsoJ/PvUvKRhJHDQXO8P8=
40+
github.com/Azure/go-ansiterm v0.0.0-20210617225240-d185dfc1b5a1/go.mod h1:xomTg63KZ2rFqZQzSB4Vz2SUXa1BpHTVz9L5PTmPC4E=
4041
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
4142
github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym/WlBOVXweHU+Q+/VP0lqqI8lqeDx9IjBqo=
4243
github.com/Microsoft/go-winio v0.6.0 h1:slsWYD/zyx7lCXoZVlvQrj0hPTM1HI4+v1sIda2yDvg=
@@ -47,6 +48,7 @@ github.com/asaskevich/govalidator v0.0.0-20200907205600-7a23bdc65eef/go.mod h1:W
4748
github.com/asaskevich/govalidator v0.0.0-20230301143203-a9d515a09cc2 h1:DklsrG3dyBCFEj5IhUbnKptjxatkF07cF2ak3yi77so=
4849
github.com/asaskevich/govalidator v0.0.0-20230301143203-a9d515a09cc2/go.mod h1:WaHUgvxTVq04UNunO+XhnAqY/wQc+bxr74GqbsZ/Jqw=
4950
github.com/benbjohnson/clock v1.3.0 h1:ip6w0uFQkncKQ979AypyG0ER7mqUSBdKLOgAle/AT8A=
51+
github.com/benbjohnson/clock v1.3.0/go.mod h1:J11/hYXuz8f4ySSvYwY0FKfm+ezbsZBKZxNJlLklBHA=
5052
github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU=
5153
github.com/chzyer/logex v1.1.10/go.mod h1:+Ywpsq7O8HXn0nuIou7OrIPyXbp3wmkHB+jjWRnGsAI=
5254
github.com/chzyer/readline v0.0.0-20180603132655-2972be24d48e/go.mod h1:nSuG5e5PlCu98SY8svDHJxuZscDgtXS6KTTbou5AhLI=
@@ -75,6 +77,7 @@ github.com/envoyproxy/go-control-plane v0.9.7/go.mod h1:cwu0lG7PUMfa9snN8LXBig5y
7577
github.com/envoyproxy/go-control-plane v0.9.9-0.20201210154907-fd9021fe5dad/go.mod h1:cXg6YxExXjJnVBQHBLXeUAgxn2UodCpnH306RInaBQk=
7678
github.com/envoyproxy/protoc-gen-validate v0.1.0/go.mod h1:iSmxcyjqTsJpI2R4NaDN7+kN2VEUnK/pcBlmesArF7c=
7779
github.com/frankban/quicktest v1.14.3 h1:FJKSZTDHjyhriyC81FLQ0LY93eSai0ZyR/ZIkd3ZUKE=
80+
github.com/frankban/quicktest v1.14.3/go.mod h1:mgiwOwqx65TmIk1wJ6Q7wvnVMocbUorkibMOrVTHZps=
7881
github.com/fsnotify/fsnotify v1.6.0 h1:n+5WquG0fcWoWp6xPWfHdbskMCQaFnG6PfBrh1Ky4HY=
7982
github.com/fsnotify/fsnotify v1.6.0/go.mod h1:sl3t1tCWJFWoRz9R8WJCbQihKKwmorjAbSClcnxKAGw=
8083
github.com/go-chi/chi/v5 v5.0.8 h1:lD+NLqFcAi1ovnVZpsnObHGW4xb4J8lNmoYVfECH1Y0=
@@ -185,6 +188,7 @@ github.com/google/go-cmp v0.5.2/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/
185188
github.com/google/go-cmp v0.5.4/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
186189
github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
187190
github.com/google/go-cmp v0.5.9 h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38=
191+
github.com/google/go-cmp v0.5.9/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
188192
github.com/google/martian v2.1.0+incompatible/go.mod h1:9I4somxYTbIHy5NJKHRl3wXiIaQGbYVAs8BPL6v8lEs=
189193
github.com/google/martian/v3 v3.0.0/go.mod h1:y5Zk1BBys9G+gd6Jrk0W3cC1+ELVxBWuIGO+w/tUAp0=
190194
github.com/google/martian/v3 v3.1.0/go.mod h1:y5Zk1BBys9G+gd6Jrk0W3cC1+ELVxBWuIGO+w/tUAp0=
@@ -241,6 +245,7 @@ github.com/konsorten/go-windows-terminal-sequences v1.0.2/go.mod h1:T0+1ngSBFLxv
241245
github.com/kr/fs v0.1.0/go.mod h1:FFnZGqtBN9Gxj7eW1uZ42v5BccTP0vu6NEaFoC2HwRg=
242246
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
243247
github.com/kr/pretty v0.3.0 h1:WgNl7dwNpEZ6jJ9k1snq4pZsg7DOEN8hP9Xw0Tsjwk0=
248+
github.com/kr/pretty v0.3.0/go.mod h1:640gp4NfQd8pI5XOwp5fnNeVWj67G7CFk/SaSQn7NBk=
244249
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
245250
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
246251
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
@@ -296,6 +301,7 @@ github.com/rogpeppe/go-internal v1.1.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFR
296301
github.com/rogpeppe/go-internal v1.2.2/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4=
297302
github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4=
298303
github.com/rogpeppe/go-internal v1.6.1 h1:/FiVV8dS/e+YqF2JvO3yXRFbBLTIuSDkuC7aBOAvL+k=
304+
github.com/rogpeppe/go-internal v1.6.1/go.mod h1:xXDCJY+GAPziupqXw64V24skbSoqbTEfhy4qGm1nDQc=
299305
github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
300306
github.com/samber/lo v1.38.1 h1:j2XEAqXKb09Am4ebOg31SpvzUTTs6EN3VfgeLUhPdXM=
301307
github.com/samber/lo v1.38.1/go.mod h1:+m/ZKRl6ClXCE2Lgf3MsQlWfh4bn1bz6CXEOxnEXnEA=
@@ -366,7 +372,6 @@ go.uber.org/dig v1.17.0 h1:5Chju+tUvcC+N7N6EV08BJz41UZuO3BmHcN4A287ZLI=
366372
go.uber.org/dig v1.17.0/go.mod h1:rTxpf7l5I0eBTlE6/9RL+lDybC7WFwY2QH55ZSjy1mU=
367373
go.uber.org/fx v1.20.0 h1:ZMC/pnRvhsthOZh9MZjMq5U8Or3mA9zBSPaLnzs3ihQ=
368374
go.uber.org/fx v1.20.0/go.mod h1:qCUj0btiR3/JnanEr1TYEePfSw6o/4qYJscgvzQ5Ub0=
369-
go.uber.org/goleak v1.1.11 h1:wy28qYRKZgnJTxGxvye5/wgWr1EKjmUDGYox5mGlRlI=
370375
go.uber.org/goleak v1.3.0 h1:2K3zAYmnTNqV73imy9J1T3WC+gmCePx2hEGkimedGto=
371376
go.uber.org/goleak v1.3.0/go.mod h1:CoHD4mav9JJNrW/WLlf7HGZPjdw8EucARQHekz1X6bE=
372377
go.uber.org/multierr v1.8.0 h1:dg6GjLku4EH+249NNmoIciG9N/jURbDG+pFlTkhzIC8=
@@ -481,6 +486,7 @@ golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJ
481486
golang.org/x/sync v0.0.0-20201207232520-09787c993a3a/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
482487
golang.org/x/sync v0.0.0-20210220032951-036812b2e83c/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
483488
golang.org/x/sync v0.3.0 h1:ftCYgMx6zT/asHUrPw8BLLscYtGznsLAnjq5RH9P66E=
489+
golang.org/x/sync v0.3.0/go.mod h1:FU7BRWz2tNW+3quACPkgCx/L+uEAv1htQ0V83Z9Rj+Y=
484490
golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
485491
golang.org/x/sys v0.0.0-20180905080454-ebe1bf3edb33/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
486492
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
@@ -529,6 +535,7 @@ golang.org/x/sys v0.11.0 h1:eG7RXZHdqOJ1i+0lgLgCpSXAp6M3LYlAo6osgSi0xOM=
529535
golang.org/x/sys v0.11.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
530536
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
531537
golang.org/x/term v0.11.0 h1:F9tnn/DA/Im8nCwm+fX+1/eBwi4qFjRT++MhtVC4ZX0=
538+
golang.org/x/term v0.11.0/go.mod h1:zC9APTIj3jG3FdV/Ons+XE1riIZXG4aZ4GTHiPZJPIU=
532539
golang.org/x/text v0.0.0-20170915032832-14c0d48ead0c/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
533540
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
534541
golang.org/x/text v0.3.1-0.20180807135948-17ff2d5776d2/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
@@ -544,6 +551,7 @@ golang.org/x/time v0.0.0-20181108054448-85acf8d2951c/go.mod h1:tRJNPiyCQ0inRvYxb
544551
golang.org/x/time v0.0.0-20190308202827-9d24e82272b4/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
545552
golang.org/x/time v0.0.0-20191024005414-555d28b269f0/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
546553
golang.org/x/time v0.1.0 h1:xYY+Bajn2a7VBmTM5GikTmnK8ZuX8YgnQCqZpbBNtmA=
554+
golang.org/x/time v0.1.0/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
547555
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
548556
golang.org/x/tools v0.0.0-20190114222345-bf090417da8b/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
549557
golang.org/x/tools v0.0.0-20190226205152-f727befe758c/go.mod h1:9Yl7xja0Znq3iFh3HoIrodX9oNMXvdceNzlUR8zjMvY=
@@ -695,6 +703,7 @@ gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8
695703
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
696704
gopkg.in/check.v1 v1.0.0-20200227125254-8fa46927fb4f/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
697705
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk=
706+
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q=
698707
gopkg.in/errgo.v2 v2.1.0/go.mod h1:hNsd1EY+bozCKY1Ytp96fpM3vjJbqLJn88ws8XvfDNI=
699708
gopkg.in/ini.v1 v1.67.0 h1:Dgnx+6+nfE+IfzjUEISNeydPJh9AXNNsWbGP9KzCsOA=
700709
gopkg.in/ini.v1 v1.67.0/go.mod h1:pNLf8WUiyNEtQjuu5G5vTm06TEv9tsIgeAvK8hOrP4k=

internal/agent/agent.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,9 @@ func New(config *Config, e engine.Engine, ds persistence.DataStoreFactory) *Agen
6363

6464
// Config contains the configuration for an Agent.
6565
type Config struct {
66-
DAG *dag.DAG
67-
Dry bool
66+
DAG *dag.DAG
67+
DAGsDir string
68+
Dry bool
6869

6970
// RetryTarget is the status to retry.
7071
RetryTarget *model.Status
@@ -337,7 +338,7 @@ func (a *Agent) run(ctx context.Context) error {
337338
utils.LogErr("write status", a.historyStore.Write(a.Status()))
338339
}()
339340

340-
ctx = dag.NewContext(ctx, a.DAG)
341+
ctx = dag.NewContext(ctx, a.DAG, a.dataStoreFactory.NewDAGStore())
341342

342343
lastErr := a.scheduler.Schedule(ctx, a.graph, done)
343344
status := a.Status()
@@ -369,7 +370,7 @@ func (a *Agent) dryRun() error {
369370

370371
log.Printf("***** Starting DRY-RUN *****")
371372

372-
ctx := dag.NewContext(context.Background(), a.DAG)
373+
ctx := dag.NewContext(context.Background(), a.DAG, a.dataStoreFactory.NewDAGStore())
373374

374375
lastErr := a.scheduler.Schedule(ctx, a.graph, done)
375376
status := a.Status()

internal/agent/agent_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ func setupTest(t *testing.T) (string, engine.Engine, persistence.DataStoreFactor
3636
DataDir: path.Join(tmpDir, ".dagu", "data"),
3737
})
3838

39-
e := engine.NewFactory(ds, nil).Create()
39+
e := engine.NewFactory(ds, config.Get()).Create()
4040

4141
return tmpDir, e, ds
4242
}

internal/config/config.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ type Config struct {
1414
Host string
1515
Port int
1616
DAGs string
17-
Command string
17+
Executable string
1818
WorkDir string
1919
IsBasicAuth bool
2020
BasicAuthUsername string
@@ -81,7 +81,7 @@ func LoadConfig() error {
8181
viper.SetEnvPrefix("dagu")
8282
viper.SetEnvKeyReplacer(strings.NewReplacer("-", "_"))
8383

84-
_ = viper.BindEnv("command", "DAGU_EXECUTABLE")
84+
_ = viper.BindEnv("executable", "DAGU_EXECUTABLE")
8585
_ = viper.BindEnv("dags", "DAGU_DAGS_DIR")
8686
_ = viper.BindEnv("workDir", "DAGU_WORK_DIR")
8787
_ = viper.BindEnv("isBasicAuth", "DAGU_IS_BASICAUTH")
@@ -100,14 +100,15 @@ func LoadConfig() error {
100100
_ = viper.BindEnv("isAuthToken", "DAGU_IS_AUTHTOKEN")
101101
_ = viper.BindEnv("authToken", "DAGU_AUTHTOKEN")
102102
_ = viper.BindEnv("latestStatusToday", "DAGU_LATEST_STATUS")
103-
command := "dagu"
104-
if ex, err := os.Executable(); err == nil {
105-
command = ex
103+
104+
executable, err := os.Executable()
105+
if err != nil {
106+
return fmt.Errorf("failed to get executable path: %w", err)
106107
}
107108

108109
viper.SetDefault("host", "127.0.0.1")
109110
viper.SetDefault("port", "8080")
110-
viper.SetDefault("command", command)
111+
viper.SetDefault("executable", executable)
111112
viper.SetDefault("dags", path.Join(appHome, "dags"))
112113
viper.SetDefault("workDir", "")
113114
viper.SetDefault("isBasicAuth", "0")
@@ -130,8 +131,7 @@ func LoadConfig() error {
130131
_ = viper.ReadInConfig()
131132

132133
cfg := &Config{}
133-
err := viper.Unmarshal(cfg)
134-
if err != nil {
134+
if err := viper.Unmarshal(cfg); err != nil {
135135
return fmt.Errorf("failed to unmarshal cfg file: %w", err)
136136
}
137137
loadLegacyEnvs(cfg)

0 commit comments

Comments
 (0)