forked from choria-io/go-choria
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
(choria-io#2209) Adds basic executor command with signal and info
Signed-off-by: R.I.Pienaar <[email protected]>
- Loading branch information
Showing
4 changed files
with
182 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
// Copyright (c) 2025, R.I. Pienaar and the Choria Project contributors | ||
// | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
package cmd | ||
|
||
import "sync" | ||
|
||
type execCommand struct { | ||
command | ||
} | ||
|
||
func (c *execCommand) Setup() (err error) { | ||
c.cmd = cli.app.Command("executor", "Long running process executor management").Alias("exec") | ||
|
||
return nil | ||
} | ||
|
||
func (c *execCommand) Configure() error { | ||
return nil | ||
} | ||
func (c *execCommand) Run(wg *sync.WaitGroup) (err error) { | ||
defer wg.Done() | ||
|
||
return nil | ||
} | ||
|
||
func init() { | ||
cli.commands = append(cli.commands, &execCommand{}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
// Copyright (c) 2025, R.I. Pienaar and the Choria Project contributors | ||
// | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
package cmd | ||
|
||
import ( | ||
"github.com/choria-io/go-choria/client/discovery" | ||
"github.com/choria-io/go-choria/client/executorclient" | ||
"os" | ||
"sync" | ||
) | ||
|
||
type executorInfoCommand struct { | ||
command | ||
|
||
fo *discovery.StandardOptions | ||
|
||
id string | ||
json bool | ||
} | ||
|
||
func init() { | ||
cli.commands = append(cli.commands, &executorInfoCommand{}) | ||
} | ||
|
||
func (n *executorInfoCommand) Setup() error { | ||
if exec, ok := cmdWithFullCommand("executor"); ok { | ||
n.cmd = exec.Cmd().Command("info", "Retrieves Job Information") | ||
n.cmd.Arg("id", "The Job ID to retrieves information for").Required().StringVar(&n.id) | ||
n.cmd.Flag("json", "Renders result in JSON format").UnNegatableBoolVar(&n.json) | ||
|
||
n.fo = discovery.NewStandardOptions() | ||
n.fo.AddFilterFlags(n.cmd) | ||
n.fo.AddFlatFileFlags(n.cmd) | ||
n.fo.AddSelectionFlags(n.cmd) | ||
} | ||
|
||
return nil | ||
} | ||
|
||
func (n *executorInfoCommand) Configure() (err error) { | ||
return commonConfigure() | ||
} | ||
|
||
func (n *executorInfoCommand) Run(wg *sync.WaitGroup) (err error) { | ||
defer wg.Done() | ||
|
||
n.fo.SetDefaultsFromChoria(c) | ||
log := c.Logger("executor") | ||
|
||
opts := []executorclient.InitializationOption{ | ||
executorclient.Logger(log), executorclient.Discovery(executorclient.NewMetaNS(n.fo, true)), | ||
} | ||
if !n.json { | ||
opts = append(opts, executorclient.Progress()) | ||
} | ||
|
||
ec, err := executorclient.New(c, opts...) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
res, err := ec.Status(n.id).Do(ctx) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
format := executorclient.TextFormat | ||
if n.json { | ||
format = executorclient.JSONFormat | ||
} | ||
return res.RenderResults(os.Stdout, format, executorclient.DisplayDDL, debug, false, true, log) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
// Copyright (c) 2025, R.I. Pienaar and the Choria Project contributors | ||
// | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
package cmd | ||
|
||
import ( | ||
"github.com/choria-io/go-choria/client/discovery" | ||
"github.com/choria-io/go-choria/client/executorclient" | ||
"os" | ||
"sync" | ||
) | ||
|
||
type executorSignalCommand struct { | ||
command | ||
|
||
fo *discovery.StandardOptions | ||
|
||
id string | ||
sig uint | ||
json bool | ||
} | ||
|
||
func init() { | ||
cli.commands = append(cli.commands, &executorSignalCommand{}) | ||
} | ||
|
||
func (s *executorSignalCommand) Setup() error { | ||
if exec, ok := cmdWithFullCommand("executor"); ok { | ||
s.cmd = exec.Cmd().Command("signal", "Retrieves Job Information").Alias("sig").Alias("kill") | ||
s.cmd.Arg("signal", "The signal to send").Required().UintVar(&s.sig) | ||
s.cmd.Arg("id", "The Job ID to signal").Required().StringVar(&s.id) | ||
s.cmd.Flag("json", "Renders result in JSON format").UnNegatableBoolVar(&s.json) | ||
|
||
s.fo = discovery.NewStandardOptions() | ||
s.fo.AddFilterFlags(s.cmd) | ||
s.fo.AddFlatFileFlags(s.cmd) | ||
s.fo.AddSelectionFlags(s.cmd) | ||
} | ||
|
||
return nil | ||
} | ||
|
||
func (s *executorSignalCommand) Configure() (err error) { | ||
return commonConfigure() | ||
} | ||
|
||
func (s *executorSignalCommand) Run(wg *sync.WaitGroup) (err error) { | ||
defer wg.Done() | ||
|
||
s.fo.SetDefaultsFromChoria(c) | ||
log := c.Logger("executor") | ||
|
||
opts := []executorclient.InitializationOption{ | ||
executorclient.Logger(log), executorclient.Discovery(executorclient.NewMetaNS(s.fo, true)), | ||
} | ||
if !s.json { | ||
opts = append(opts, executorclient.Progress()) | ||
} | ||
|
||
ec, err := executorclient.New(c, opts...) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
res, err := ec.Signal(s.id, int64(s.sig)).Do(ctx) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
format := executorclient.TextFormat | ||
if s.json { | ||
format = executorclient.JSONFormat | ||
} | ||
return res.RenderResults(os.Stdout, format, executorclient.DisplayDDL, debug, false, true, log) | ||
} |