feat: added script support when updating tasks for the cloud (#433)

* feat: added script support when updating tasks for the cloud

* feat: added script ID to task printing
This commit is contained in:
Andrew Depke 2022-08-03 13:12:27 -06:00 committed by GitHub
parent 1453e20f2b
commit 826e03f8b2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 47 additions and 7 deletions

View File

@ -300,11 +300,22 @@ func (c Client) Update(ctx context.Context, params *UpdateParams) error {
}
status = &s
}
scriptID := &params.ScriptID
if len(params.ScriptID) == 0 {
scriptID = nil
}
scriptParams := &params.ScriptParams
if len(params.ScriptParams) == 0 {
scriptParams = nil
}
task, err := c.PatchTasksID(ctx, params.TaskID).TaskUpdateRequest(api.TaskUpdateRequest{
Status: status,
Flux: flux,
ScriptID: &params.ScriptID,
ScriptParameters: &params.ScriptParams,
ScriptID: scriptID,
ScriptParameters: scriptParams,
}).Execute()
if err != nil {
return err
@ -361,6 +372,7 @@ func (c Client) printTasks(printOpts taskPrintOpts) error {
"Status",
"Every",
"Cron",
"ScriptID",
}
if printOpts.task != nil {

View File

@ -211,6 +211,8 @@ func newTaskRetryFailedCmd() cli.Command {
func newTaskUpdateCmd() cli.Command {
var params task.UpdateParams
var scriptID string
var scriptParams string
flags := commonFlags()
flags = append(flags, []cli.Flag{
&cli.StringFlag{
@ -229,6 +231,16 @@ func newTaskUpdateCmd() cli.Command {
Usage: "Path to Flux script file",
TakesFile: true,
},
&cli.StringFlag{
Name: "script-id",
Usage: "[Cloud only] Path to Flux script file",
Destination: &scriptID,
},
&cli.StringFlag{
Name: "script-params",
Usage: "[Cloud only] Path to Flux script file",
Destination: &scriptParams,
},
}...)
return cli.Command{
Name: "update",
@ -237,16 +249,32 @@ func newTaskUpdateCmd() cli.Command {
Flags: flags,
Before: middleware.WithBeforeFns(withCli(), withApi(true), middleware.NoArgs),
Action: func(ctx *cli.Context) error {
fluxFile := ctx.String("file")
if len(fluxFile) > 0 && len(scriptID) > 0 {
return errors.New("cannot specify both Flux from a file and a script ID")
}
api := getAPI(ctx)
client := task.Client{
CLI: getCLI(ctx),
TasksApi: api.TasksApi,
}
var err error
if ctx.String("file") != "" || ctx.NArg() != 0 {
params.FluxQuery, err = clients.ReadQuery(ctx.String("file"), ctx.Args())
if err != nil {
return err
if len(fluxFile) > 0 {
var err error
if ctx.String("file") != "" || ctx.NArg() != 0 {
params.FluxQuery, err = clients.ReadQuery(ctx.String("file"), ctx.Args())
if err != nil {
return err
}
}
} else {
params.ScriptID = scriptID
params.ScriptParams = make(map[string]interface{})
if len(scriptParams) > 0 {
if err := json.NewDecoder(strings.NewReader(scriptParams)).Decode(&params.ScriptParams); err != nil {
return err
}
}
}
return client.Update(getContext(ctx), &params)