mirror of
https://github.com/dagucloud/dagu.git
synced 2026-12-05 21:34:48 +00:00
74 lines
2.0 KiB
Go
74 lines
2.0 KiB
Go
// Copyright (C) 2024 The Dagu Authors
|
|
//
|
|
// This program is free software: you can redistribute it and/or modify
|
|
// it under the terms of the GNU General Public License as published by
|
|
// the Free Software Foundation, either version 3 of the License, or
|
|
// (at your option) any later version.
|
|
//
|
|
// This program is distributed in the hope that it will be useful,
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
// GNU General Public License for more details.
|
|
//
|
|
// You should have received a copy of the GNU General Public License
|
|
// along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
|
|
package cmd
|
|
|
|
import (
|
|
"log"
|
|
|
|
"github.com/dagu-org/dagu/internal/config"
|
|
"github.com/dagu-org/dagu/internal/dag"
|
|
"github.com/dagu-org/dagu/internal/logger"
|
|
"github.com/spf13/cobra"
|
|
)
|
|
|
|
func stopCmd() *cobra.Command {
|
|
cmd := &cobra.Command{
|
|
Use: "stop /path/to/spec.yaml",
|
|
Short: "Stop the running workflow",
|
|
Long: `dagu stop /path/to/spec.yaml`,
|
|
Args: cobra.ExactArgs(1),
|
|
Run: func(cmd *cobra.Command, args []string) {
|
|
cfg, err := config.Load()
|
|
if err != nil {
|
|
log.Fatalf("Configuration load failed: %v", err)
|
|
}
|
|
|
|
quiet, err := cmd.Flags().GetBool("quiet")
|
|
if err != nil {
|
|
log.Fatalf("Flag retrieval failed (quiet): %v", err)
|
|
}
|
|
|
|
logger := logger.NewLogger(logger.NewLoggerArgs{
|
|
Debug: cfg.Debug,
|
|
Format: cfg.LogFormat,
|
|
Quiet: quiet,
|
|
})
|
|
|
|
workflow, err := dag.Load(cfg.BaseConfig, args[0], "")
|
|
if err != nil {
|
|
logger.Fatal("Workflow load failed", "error", err, "file", args[0])
|
|
}
|
|
|
|
logger.Info("Workflow stop initiated", "workflow", workflow.Name)
|
|
|
|
dataStore := newDataStores(cfg)
|
|
cli := newClient(cfg, dataStore, logger)
|
|
|
|
if err := cli.Stop(workflow); err != nil {
|
|
logger.Fatal(
|
|
"Workflow stop operation failed",
|
|
"error",
|
|
err,
|
|
"workflow",
|
|
workflow.Name,
|
|
)
|
|
}
|
|
},
|
|
}
|
|
cmd.Flags().BoolP("quiet", "q", false, "suppress output")
|
|
return cmd
|
|
}
|