Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var CleanCmd = &cobra.Command{ Use: "clean", Short: "Clean all finished task.", Run: func(cmd *cobra.Command, args []string) { c := &config.Config{} c.LoadFromFilePath(cmd.Flag("config").Value.String()) err := c.Check() if err != nil { logrus.Errorf("Config check failed for %v.", err) return } if pidfile := c.PIDFile; pidfile != "" { p, err := pid.New(pidfile) if err != nil { logrus.Errorf("PID create failed for %v.", err) return } defer func() { err = p.Remove() if err != nil { logrus.Errorf("PID remove failed for %v.", err) } }() } err = contexts.SetupContexts(c) if err != nil { logrus.Errorf("Contexts setup failed for %v.", err) return } defer contexts.DB.Close() logrus.Infof("Clean started.") ctx := context.Background() t, err := model.ListTask(ctx) if err != nil { logrus.Panic(err) } for _, v := range t { if v.Status != constants.TaskStatusFinished { continue } err = model.DeleteTaskByName(ctx, v.Name) if err != nil { logrus.Panic(err) } logrus.Infof("Task %s has been cleaned.", v.Name) } }, }
CleanCmd will clean all finished task.
View Source
var DeleteCmd = &cobra.Command{ Use: "delete [task name]", Short: "Delete a task", Args: cobra.ExactArgs(1), Run: func(cmd *cobra.Command, args []string) { c := &config.Config{} c.LoadFromFilePath(cmd.Flag("config").Value.String()) err := c.Check() if err != nil { logrus.Errorf("Config check failed for %v.", err) return } if pidfile := c.PIDFile; pidfile != "" { p, err := pid.New(pidfile) if err != nil { logrus.Errorf("PID create failed for %v.", err) return } defer func() { err = p.Remove() if err != nil { logrus.Errorf("PID remove failed for %v.", err) } }() } err = contexts.SetupContexts(c) if err != nil { logrus.Errorf("Contexts setup failed for %v.", err) return } defer contexts.DB.Close() ctx := context.Background() t, err := model.GetTaskByName(ctx, args[0]) if err != nil { logrus.Panicf("Task load failed for %v.", err) return } if t == nil { logrus.Errorf("Task %s is not exist.", args[0]) return } ctx = utils.NewTaskContext(ctx, t.Name) logrus.Infof("Task %s delete started.", t.Name) err = model.DeleteTask(ctx) if err != nil { logrus.Panicf("Delete task for %v.", err) } logrus.Infof("Task %s has been deleted.", t.Name) }, }
DeleteCmd will provide delete command for qscamel.
View Source
var RunCmd = &cobra.Command{ Use: "run [task name or task path]", Short: "Create or resume a task", Args: cobra.ExactArgs(1), Run: func(cmd *cobra.Command, args []string) { c := &config.Config{} c.LoadFromFilePath(cmd.Flag("config").Value.String()) err := c.Check() if err != nil { logrus.Errorf("Config check failed for %v.", err) return } if pidfile := c.PIDFile; pidfile != "" { p, err := pid.New(pidfile) if err != nil { logrus.Errorf("PID create failed for %v.", err) return } defer func() { err = p.Remove() if err != nil { logrus.Errorf("PID remove failed for %v.", err) } }() } err = contexts.SetupContexts(c) if err != nil { logrus.Errorf("Contexts setup failed for %v.", err) return } defer contexts.DB.Close() ctx := context.Background() sigs := make(chan os.Signal, 1) signal.Notify(sigs, os.Interrupt, os.Kill) go func() { sig := <-sigs logrus.Infof("Signal %v received, exit for now.", sig) contexts.DB.Close() os.Exit(0) }() t, err := model.LoadTask(args[0]) if err != nil { logrus.Errorf("Task load failed for %v.", err) return } err = t.Check() if err != nil { logrus.Errorf("Task check failed for %v.", err) return } ctx = utils.NewTaskContext(ctx, t.Name) logrus.Infof("Current version: %s.", constants.Version) logrus.Infof("Task %s migrate started.", t.Name) err = migrate.Execute(ctx) if err != nil { logrus.Errorf("Migrate failed for %v.", err) } }, }
RunCmd will provide run command for qscamel.
View Source
var StatusCmd = &cobra.Command{ Use: "status", Short: "Show current task status.", Run: func(cmd *cobra.Command, args []string) { c := &config.Config{} c.LoadFromFilePath(cmd.Flag("config").Value.String()) err := c.Check() if err != nil { logrus.Errorf("Config check failed for %v.", err) return } if pidfile := c.PIDFile; pidfile != "" { p, err := pid.New(pidfile) if err != nil { logrus.Errorf("PID create failed for %v.", err) return } defer func() { err = p.Remove() if err != nil { logrus.Errorf("PID remove failed for %v.", err) } }() } err = contexts.SetupContexts(c) if err != nil { logrus.Errorf("Contexts setup failed for %v.", err) return } defer contexts.DB.Close() logrus.Infof("Show status started.") ctx := context.Background() t, err := model.ListTask(ctx) if err != nil { logrus.Panic(err) } logrus.Printf("There are %d tasks totally.", len(t)) for _, v := range t { logrus.Printf("Task: %s, Status: %s", v.Name, v.Status) } }, }
StatusCmd will show current task status.
View Source
var VersionCmd = &cobra.Command{ Use: "version", Short: "Print the version number of qscamel", Run: func(cmd *cobra.Command, args []string) { fmt.Printf("%s version %s\n", constants.Name, constants.Version) }, }
VersionCmd will provide version command for qscamel.
Functions ¶
This section is empty.
Types ¶
This section is empty.
Click to show internal directories.
Click to hide internal directories.