/
schedule_flow.go
70 lines (58 loc) · 1.61 KB
/
schedule_flow.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
package command
import (
"bytes"
"fmt"
"github.com/jessevdk/go-flags"
"github.com/mitchellh/cli"
"github.com/prokosna/dementor/lib"
)
type ScheduleFlowCommand struct {
Ui cli.Ui
}
var scheduleFlowOpts struct {
ProjectName string `short:"p" long:"project" description:"Project name" required:"true"`
Flow string `short:"f" long:"flowId" description:"Flow ID" required:"true"`
CronExpression string `short:"c" long:"cron" description:"Cron expression such as 0 23/30 5,7-10 ? * 6#3" required:"true"`
dementor.CommonConf
}
var scheduleFlowParser *flags.Parser
func init() {
scheduleFlowParser = flags.NewParser(&scheduleFlowOpts, flags.IgnoreUnknown|flags.HelpFlag|flags.PassDoubleDash)
}
func (c *ScheduleFlowCommand) Run(args []string) int {
_, err := scheduleFlowParser.ParseArgs(args)
if err != nil {
c.Ui.Error(err.Error())
c.Ui.Output(c.Help())
return 1
}
id, err := getSessionId(scheduleFlowOpts.CommonConf)
if err != nil {
c.Ui.Error(err.Error())
return 1
}
req := &dementor.ScheduleFlowReq{
ProjectName: scheduleFlowOpts.ProjectName,
Flow: scheduleFlowOpts.Flow,
CronExpression: scheduleFlowOpts.CronExpression,
CommonConf: scheduleFlowOpts.CommonConf,
}
res, err := dementor.ScheduleFlow(
id,
req,
)
if err != nil {
c.Ui.Error(err.Error())
return 1
}
c.Ui.Info(fmt.Sprintf("Successfully scheduled the flow [%s]", res.ScheduleId))
return 0
}
func (c *ScheduleFlowCommand) Help() string {
buf := new(bytes.Buffer)
scheduleFlowParser.WriteHelp(buf)
return buf.String()
}
func (c *ScheduleFlowCommand) Synopsis() string {
return "Schedule the flow."
}