-
Notifications
You must be signed in to change notification settings - Fork 24
/
cronjob_cancel.go
78 lines (62 loc) · 2.44 KB
/
cronjob_cancel.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
71
72
73
74
75
76
77
78
package cmd
import (
"context"
"fmt"
"github.com/pterm/pterm"
"github.com/spf13/cobra"
"os"
"github.com/qovery/qovery-cli/utils"
)
var cronjobCancelCmd = &cobra.Command{
Use: "cancel",
Short: "Cancel a cronjob deployment",
Run: func(cmd *cobra.Command, args []string) {
utils.Capture(cmd)
tokenType, token, err := utils.GetAccessToken()
if err != nil {
utils.PrintlnError(err)
os.Exit(1)
panic("unreachable") // staticcheck false positive: https://staticcheck.io/docs/checks#SA5011
}
client := utils.GetQoveryClient(tokenType, token)
_, _, envId, err := getOrganizationProjectEnvironmentContextResourcesIds(client)
if err != nil {
utils.PrintlnError(err)
os.Exit(1)
panic("unreachable") // staticcheck false positive: https://staticcheck.io/docs/checks#SA5011
}
cronjobs, _, err := client.JobsAPI.ListJobs(context.Background(), envId).Execute()
if err != nil {
utils.PrintlnError(err)
os.Exit(1)
panic("unreachable") // staticcheck false positive: https://staticcheck.io/docs/checks#SA5011
}
cronjob := utils.FindByJobName(cronjobs.GetResults(), cronjobName)
if cronjob == nil || cronjob.CronJobResponse == nil {
utils.PrintlnError(fmt.Errorf("cronjob %s not found", cronjobName))
utils.PrintlnInfo("You can list all cronjobs with: qovery cronjob list")
os.Exit(1)
panic("unreachable") // staticcheck false positive: https://staticcheck.io/docs/checks#SA5011
}
msg, err := utils.CancelServiceDeployment(client, envId, cronjob.CronJobResponse.Id, utils.JobType, watchFlag)
if err != nil {
utils.PrintlnError(err)
os.Exit(1)
panic("unreachable") // staticcheck false positive: https://staticcheck.io/docs/checks#SA5011
}
if msg != "" {
utils.PrintlnInfo(msg)
return
}
utils.Println(fmt.Sprintf("Cronjob %s deployment cancelled!", pterm.FgBlue.Sprintf("%s", cronjobName)))
},
}
func init() {
cronjobCmd.AddCommand(cronjobCancelCmd)
cronjobCancelCmd.Flags().StringVarP(&organizationName, "organization", "", "", "Organization Name")
cronjobCancelCmd.Flags().StringVarP(&projectName, "project", "", "", "Project Name")
cronjobCancelCmd.Flags().StringVarP(&environmentName, "environment", "", "", "Environment Name")
cronjobCancelCmd.Flags().StringVarP(&cronjobName, "cronjob", "n", "", "Cronjob Name")
cronjobCancelCmd.Flags().BoolVarP(&watchFlag, "watch", "w", false, "Watch cancel until it's done or an error occurs")
_ = cronjobCancelCmd.MarkFlagRequired("cronjob")
}