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:
@ -300,11 +300,22 @@ func (c Client) Update(ctx context.Context, params *UpdateParams) error {
|
|||||||
}
|
}
|
||||||
status = &s
|
status = &s
|
||||||
}
|
}
|
||||||
|
|
||||||
|
scriptID := ¶ms.ScriptID
|
||||||
|
if len(params.ScriptID) == 0 {
|
||||||
|
scriptID = nil
|
||||||
|
}
|
||||||
|
|
||||||
|
scriptParams := ¶ms.ScriptParams
|
||||||
|
if len(params.ScriptParams) == 0 {
|
||||||
|
scriptParams = nil
|
||||||
|
}
|
||||||
|
|
||||||
task, err := c.PatchTasksID(ctx, params.TaskID).TaskUpdateRequest(api.TaskUpdateRequest{
|
task, err := c.PatchTasksID(ctx, params.TaskID).TaskUpdateRequest(api.TaskUpdateRequest{
|
||||||
Status: status,
|
Status: status,
|
||||||
Flux: flux,
|
Flux: flux,
|
||||||
ScriptID: ¶ms.ScriptID,
|
ScriptID: scriptID,
|
||||||
ScriptParameters: ¶ms.ScriptParams,
|
ScriptParameters: scriptParams,
|
||||||
}).Execute()
|
}).Execute()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
@ -361,6 +372,7 @@ func (c Client) printTasks(printOpts taskPrintOpts) error {
|
|||||||
"Status",
|
"Status",
|
||||||
"Every",
|
"Every",
|
||||||
"Cron",
|
"Cron",
|
||||||
|
"ScriptID",
|
||||||
}
|
}
|
||||||
|
|
||||||
if printOpts.task != nil {
|
if printOpts.task != nil {
|
||||||
|
@ -211,6 +211,8 @@ func newTaskRetryFailedCmd() cli.Command {
|
|||||||
|
|
||||||
func newTaskUpdateCmd() cli.Command {
|
func newTaskUpdateCmd() cli.Command {
|
||||||
var params task.UpdateParams
|
var params task.UpdateParams
|
||||||
|
var scriptID string
|
||||||
|
var scriptParams string
|
||||||
flags := commonFlags()
|
flags := commonFlags()
|
||||||
flags = append(flags, []cli.Flag{
|
flags = append(flags, []cli.Flag{
|
||||||
&cli.StringFlag{
|
&cli.StringFlag{
|
||||||
@ -229,6 +231,16 @@ func newTaskUpdateCmd() cli.Command {
|
|||||||
Usage: "Path to Flux script file",
|
Usage: "Path to Flux script file",
|
||||||
TakesFile: true,
|
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{
|
return cli.Command{
|
||||||
Name: "update",
|
Name: "update",
|
||||||
@ -237,16 +249,32 @@ func newTaskUpdateCmd() cli.Command {
|
|||||||
Flags: flags,
|
Flags: flags,
|
||||||
Before: middleware.WithBeforeFns(withCli(), withApi(true), middleware.NoArgs),
|
Before: middleware.WithBeforeFns(withCli(), withApi(true), middleware.NoArgs),
|
||||||
Action: func(ctx *cli.Context) error {
|
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)
|
api := getAPI(ctx)
|
||||||
client := task.Client{
|
client := task.Client{
|
||||||
CLI: getCLI(ctx),
|
CLI: getCLI(ctx),
|
||||||
TasksApi: api.TasksApi,
|
TasksApi: api.TasksApi,
|
||||||
}
|
}
|
||||||
var err error
|
if len(fluxFile) > 0 {
|
||||||
if ctx.String("file") != "" || ctx.NArg() != 0 {
|
var err error
|
||||||
params.FluxQuery, err = clients.ReadQuery(ctx.String("file"), ctx.Args())
|
if ctx.String("file") != "" || ctx.NArg() != 0 {
|
||||||
if err != nil {
|
params.FluxQuery, err = clients.ReadQuery(ctx.String("file"), ctx.Args())
|
||||||
return err
|
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(¶ms.ScriptParams); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return client.Update(getContext(ctx), ¶ms)
|
return client.Update(getContext(ctx), ¶ms)
|
||||||
|
Reference in New Issue
Block a user