Skip to content

Commit

Permalink
admin: organize DAG loading code
Browse files Browse the repository at this point in the history
  • Loading branch information
yottahmd committed Aug 10, 2022
1 parent 00b9949 commit ff88a2a
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 15 deletions.
7 changes: 7 additions & 0 deletions cmd/dagu.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (

"github.com/urfave/cli/v2"
"github.com/yohamta/dagu/internal/admin"
"github.com/yohamta/dagu/internal/config"
"github.com/yohamta/dagu/internal/constants"
"github.com/yohamta/dagu/internal/utils"
)
Expand All @@ -30,6 +31,12 @@ func main() {
}
}

func loadDAG(dagPath, params string) (cfg *config.Config, err error) {
cl := &config.Loader{BaseConfig: globalConfig.BaseConfig}
cfg, err = cl.Load(dagPath, params)
return
}

func listenSignals(abortFunc func(sig os.Signal)) {
sigs = make(chan os.Signal, 1)
signal.Notify(sigs, syscall.SIGINT, syscall.SIGTERM)
Expand Down
4 changes: 1 addition & 3 deletions cmd/dry.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,7 @@ func newDryCommand() *cli.Command {
},
},
Action: func(c *cli.Context) error {
config_file_path := c.Args().Get(0)
cl := &config.Loader{BaseConfig: globalConfig.BaseConfig}
cfg, err := cl.Load(config_file_path, c.String("params"))
cfg, err := loadDAG(c.Args().Get(0), c.String("params"))
if err != nil {
return err
}
Expand Down
5 changes: 1 addition & 4 deletions cmd/retry.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"path/filepath"

"github.com/yohamta/dagu"
"github.com/yohamta/dagu/internal/config"
"github.com/yohamta/dagu/internal/database"

"github.com/urfave/cli/v2"
Expand All @@ -32,16 +31,14 @@ func newRetryCommand() *cli.Command {
}

func retry(f, requestId string) error {
cl := &config.Loader{BaseConfig: globalConfig.BaseConfig}
db := database.Database{
Config: database.DefaultConfig(),
}
status, err := db.FindByRequestId(f, requestId)
if err != nil {
return err
}

cfg, err := cl.Load(f, status.Status.Params)
cfg, err := loadDAG(f, status.Status.Params)
if err != nil {
return err
}
Expand Down
3 changes: 1 addition & 2 deletions cmd/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,7 @@ func newStartCommand() *cli.Command {
},
Action: func(c *cli.Context) error {
config_file_path := c.Args().Get(0)
cl := &config.Loader{BaseConfig: globalConfig.BaseConfig}
cfg, err := cl.Load(config_file_path, c.String("params"))
cfg, err := loadDAG(config_file_path, c.String("params"))
if err != nil {
return err
}
Expand Down
4 changes: 1 addition & 3 deletions cmd/status.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,7 @@ func newStatusCommand() *cli.Command {
Name: "status",
Usage: "dagu status <config>",
Action: func(c *cli.Context) error {
config_file_path := c.Args().Get(0)
cl := &config.Loader{BaseConfig: globalConfig.BaseConfig}
cfg, err := cl.Load(config_file_path, "")
cfg, err := loadDAG(c.Args().Get(0), "")
if err != nil {
return err
}
Expand Down
4 changes: 1 addition & 3 deletions cmd/stop.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,7 @@ func newStopCommand() *cli.Command {
Name: "stop",
Usage: "dagu stop <config>",
Action: func(c *cli.Context) error {
config_file_path := c.Args().Get(0)
cl := &config.Loader{BaseConfig: globalConfig.BaseConfig}
cfg, err := cl.Load(config_file_path, "")
cfg, err := loadDAG(c.Args().Get(0), "")
if err != nil {
return err
}
Expand Down

0 comments on commit ff88a2a

Please sign in to comment.