Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Run update check when any client command is executed #2909

Merged
merged 1 commit into from
Oct 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 7 additions & 6 deletions cmd/cli/cancel/cancel.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,12 +53,13 @@ func NewCmd() *cobra.Command {
cancelOptions := NewCancelOptions()

cancelCmd := &cobra.Command{
Use: "cancel [id]",
Short: "Cancel a previously submitted job",
Long: cancelLong,
Example: cancelExample,
Args: cobra.ExactArgs(1),
PreRun: util.ApplyPorcelainLogLevel,
Use: "cancel [id]",
Short: "Cancel a previously submitted job",
Long: cancelLong,
Example: cancelExample,
Args: cobra.ExactArgs(1),
PreRunE: util.ClientPreRunHooks,
PostRunE: util.ClientPostRunHooks,
RunE: func(cmd *cobra.Command, cmdArgs []string) error {
return cancel(cmd, cmdArgs, cancelOptions)
},
Expand Down
13 changes: 7 additions & 6 deletions cmd/cli/create/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,12 +59,13 @@ func NewCmd() *cobra.Command {
OC := NewCreateOptions()

createCmd := &cobra.Command{
Use: "create",
Short: "Create a job using a json or yaml file.",
Long: createLong,
Example: createExample,
Args: cobra.MinimumNArgs(0),
PreRun: util.ApplyPorcelainLogLevel,
Use: "create",
Short: "Create a job using a json or yaml file.",
Long: createLong,
Example: createExample,
Args: cobra.MinimumNArgs(0),
PreRunE: util.ClientPreRunHooks,
PostRunE: util.ClientPostRunHooks,
Run: func(cmd *cobra.Command, cmdArgs []string) {
if err := create(cmd, cmdArgs, OC); err != nil {
util.Fatal(cmd, err, 1)
Expand Down
13 changes: 7 additions & 6 deletions cmd/cli/describe/describe.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,13 @@ func NewCmd() *cobra.Command {
OD := NewDescribeOptions()

describeCmd := &cobra.Command{
Use: "describe [id]",
Short: "Describe a job on the network",
Long: describeLong,
Example: describeExample,
Args: cobra.ExactArgs(1),
PreRun: util.ApplyPorcelainLogLevel,
Use: "describe [id]",
Short: "Describe a job on the network",
Long: describeLong,
Example: describeExample,
Args: cobra.ExactArgs(1),
PreRunE: util.ClientPreRunHooks,
PostRunE: util.ClientPostRunHooks,
Run: func(cmd *cobra.Command, cmdArgs []string) { // nolintunparam // incorrectly suggesting unused
if err := describe(cmd, cmdArgs, OD); err != nil {
util.Fatal(cmd, err, 1)
Expand Down
22 changes: 8 additions & 14 deletions cmd/cli/docker/docker_run.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ func NewCmd() *cobra.Command {
dockerCmd := &cobra.Command{
Use: "docker",
Short: "Run a docker job on the network (see run subcommand)",
PersistentPreRunE: util.CheckVersion,
PersistentPreRunE: util.AfterParentPreRunHook(util.CheckVersion),
}

dockerCmd.AddCommand(newDockerRunCmd())
Expand All @@ -98,19 +98,13 @@ func newDockerRunCmd() *cobra.Command { //nolint:funlen
}

dockerRunCmd := &cobra.Command{
Use: "run [flags] IMAGE[:TAG|@DIGEST] [COMMAND] [ARG...]",
Short: "Run a docker job on the network",
Long: runLong,
Example: runExample,
Args: cobra.MinimumNArgs(1),
PreRun: util.ApplyPorcelainLogLevel,
PreRunE: func(cmd *cobra.Command, args []string) error {
err := configflags.BindFlags(cmd, dockerRunFlags)
if err != nil {
util.Fatal(cmd, err, 1)
}
return err
},
Use: "run [flags] IMAGE[:TAG|@DIGEST] [COMMAND] [ARG...]",
Short: "Run a docker job on the network",
Long: runLong,
Example: runExample,
Args: cobra.MinimumNArgs(1),
PreRunE: util.Chain(util.ClientPreRunHooks, configflags.PreRun(dockerRunFlags)),
PostRunE: util.ClientPostRunHooks,
Run: func(cmd *cobra.Command, cmdArgs []string) {
if err := dockerRun(cmd, cmdArgs, opts); err != nil {
util.Fatal(cmd, err, 1)
Expand Down
19 changes: 7 additions & 12 deletions cmd/cli/get/get.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,18 +47,13 @@ func NewCmd() *cobra.Command {
}

getCmd := &cobra.Command{
Use: "get [id]",
Short: "Get the results of a job",
Long: getLong,
Example: getExample,
Args: cobra.ExactArgs(1),
PreRun: func(cmd *cobra.Command, args []string) {
if err := configflags.BindFlags(cmd, getFlags); err != nil {
util.Fatal(cmd, err, 1)
}

util.ApplyPorcelainLogLevel(cmd, args)
},
Use: "get [id]",
Short: "Get the results of a job",
Long: getLong,
Example: getExample,
Args: cobra.ExactArgs(1),
PreRunE: util.Chain(util.ClientPreRunHooks, configflags.PreRun(getFlags)),
PostRunE: util.ClientPostRunHooks,
Run: func(cmd *cobra.Command, cmdArgs []string) {
if err := get(cmd, cmdArgs, OG); err != nil {
util.Fatal(cmd, err, 1)
Expand Down
3 changes: 1 addition & 2 deletions cmd/cli/job/describe.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import (

var (
describeLong = templates.LongDesc(i18n.T(`
Full description of a job, in yaml format.
Full description of a job, in yaml format.
Use 'bacalhau job list' to get a list of jobs.
`))
describeExample = templates.Examples(i18n.T(`
Expand Down Expand Up @@ -49,7 +49,6 @@ func NewDescribeCmd() *cobra.Command {
Long: describeLong,
Example: describeExample,
Args: cobra.ExactArgs(1),
PreRun: util.ApplyPorcelainLogLevel,
Run: o.run,
}
jobCmd.Flags().AddFlagSet(cliflags.OutputNonTabularFormatFlags(&o.OutputOpts))
Expand Down
3 changes: 1 addition & 2 deletions cmd/cli/job/executions.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ var (

executionExample = templates.Examples(i18n.T(`
# All executions for a given job.
bacalhau job executions j-e3f8c209-d683-4a41-b840-f09b88d087b9
bacalhau job executions j-e3f8c209-d683-4a41-b840-f09b88d087b9
`))
)

Expand Down Expand Up @@ -58,7 +58,6 @@ func NewExecutionCmd() *cobra.Command {
Long: executionLong,
Example: executionExample,
Args: cobra.ExactArgs(1),
PreRun: util.ApplyPorcelainLogLevel,
Run: o.run,
}

Expand Down
3 changes: 1 addition & 2 deletions cmd/cli/job/history.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ var (
# Job level events
bacalhau job history --type job e3f8c209

# Execution level events
# Execution level events
bacalhau job history --type execution e3f8c209
`))
)
Expand Down Expand Up @@ -62,7 +62,6 @@ func NewHistoryCmd() *cobra.Command {
Long: historyLong,
Example: historyExample,
Args: cobra.ExactArgs(1),
PreRun: util.ApplyPorcelainLogLevel,
Run: o.run,
}

Expand Down
1 change: 0 additions & 1 deletion cmd/cli/job/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,6 @@ func NewListCmd() *cobra.Command {
Short: listShort,
Long: listLong,
Example: listExample,
PreRun: util.ApplyPorcelainLogLevel,
Args: cobra.NoArgs,
Run: o.run,
}
Expand Down
3 changes: 1 addition & 2 deletions cmd/cli/job/logs.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ var (
# Follow logs for a previously submitted job
bacalhau logs j-51225160-807e-48b8-88c9-28311c7899e1

# Follow output with a short ID
# Follow output with a short ID
bacalhau logs j-ebd9bf2f
`))
)
Expand All @@ -35,7 +35,6 @@ func NewLogCmd() *cobra.Command {
Short: logsShortDesc,
Example: logsExample,
Args: cobra.ExactArgs(1),
PreRun: util.ApplyPorcelainLogLevel,
Run: func(cmd *cobra.Command, cmdArgs []string) {
if err := util.Logs(cmd, cmdArgs[0], options.Follow, options.WithHistory); err != nil {
util.Fatal(cmd, err, 1)
Expand Down
11 changes: 8 additions & 3 deletions cmd/cli/job/root.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
package job

import "github.com/spf13/cobra"
import (
"github.com/bacalhau-project/bacalhau/cmd/util"
"github.com/spf13/cobra"
)

func NewCmd() *cobra.Command {
cmd := &cobra.Command{
Use: "job",
Short: "Commands to submit, query and update jobs.",
Use: "job",
Short: "Commands to submit, query and update jobs.",
PersistentPreRunE: util.AfterParentPreRunHook(util.ClientPreRunHooks),
PersistentPostRunE: util.AfterParentPostRunHook(util.ClientPostRunHooks),
}

cmd.AddCommand(NewDescribeCmd())
Expand Down
3 changes: 1 addition & 2 deletions cmd/cli/job/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ var (
bacalhau job run ./job.yaml

# Run a new job from an already executed job
bacalhau job describe 6e51df50 | bacalhau job run
bacalhau job describe 6e51df50 | bacalhau job run
`))
)

Expand All @@ -55,7 +55,6 @@ func NewRunCmd() *cobra.Command {
Long: runLong,
Example: runExample,
Args: cobra.MinimumNArgs(0),
PreRun: util.ApplyPorcelainLogLevel,
Run: o.run,
}

Expand Down
1 change: 0 additions & 1 deletion cmd/cli/job/stop.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@ func NewStopCmd() *cobra.Command {
Long: stopLong,
Example: stopExample,
Args: cobra.ExactArgs(1),
PreRun: util.ApplyPorcelainLogLevel,
RunE: o.run,
}

Expand Down
11 changes: 6 additions & 5 deletions cmd/cli/list/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,11 +68,12 @@ func NewCmd() *cobra.Command {
OL := NewListOptions()

listCmd := &cobra.Command{
Use: "list",
Short: "List jobs on the network",
Long: listLong,
Example: listExample,
PreRun: util.ApplyPorcelainLogLevel,
Use: "list",
Short: "List jobs on the network",
Long: listLong,
Example: listExample,
PreRunE: util.ClientPreRunHooks,
PostRunE: util.ClientPostRunHooks,
Run: func(cmd *cobra.Command, _ []string) {
if err := list(cmd, OL); err != nil {
util.Fatal(cmd, err, 1)
Expand Down
4 changes: 1 addition & 3 deletions cmd/cli/list/list_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ func (suite *ListSuite) TestList_NumberOfJobs() {
{numberOfJobs: 5, numberOfJobsOutput: 5}, // Test for 5 (less than default of 10)
{numberOfJobs: 20, numberOfJobsOutput: 10}, // Test for 20 (more than max of 10)
{numberOfJobs: 20, numberOfJobsOutput: 15}, // The default is 10 so test for non-default

}

for _, tc := range tests {
Expand All @@ -68,8 +67,7 @@ func (suite *ListSuite) TestList_NumberOfJobs() {
"--reverse", "false",
)
require.NoError(suite.T(), err)

require.Equal(suite.T(), tc.numberOfJobsOutput, strings.Count(out, "\n"))
require.Equal(suite.T(), tc.numberOfJobsOutput, strings.Count(out, "\n"), out)
})
}
}
Expand Down
9 changes: 4 additions & 5 deletions cmd/cli/node/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,10 @@ func NewListOptions() *ListOptions {
func NewListCmd() *cobra.Command {
o := NewListOptions()
nodeCmd := &cobra.Command{
Use: "list",
Short: "List info of network nodes. ",
PreRun: util.ApplyPorcelainLogLevel,
Args: cobra.NoArgs,
Run: o.run,
Use: "list",
Short: "List info of network nodes. ",
Args: cobra.NoArgs,
Run: o.run,
}
nodeCmd.Flags().StringSliceVar(&o.ColumnGroups, "show", o.ColumnGroups,
fmt.Sprintf("What column groups to show. Zero or more of: %q", maps.Keys(toggleColumns)))
Expand Down
11 changes: 8 additions & 3 deletions cmd/cli/node/root.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
package node

import "github.com/spf13/cobra"
import (
"github.com/bacalhau-project/bacalhau/cmd/util"
"github.com/spf13/cobra"
)

func NewCmd() *cobra.Command {
cmd := &cobra.Command{
Use: "node",
Short: "Commands to query and update nodes information.",
Use: "node",
Short: "Commands to query and update nodes information.",
PersistentPreRunE: util.AfterParentPreRunHook(util.ClientPreRunHooks),
PersistentPostRunE: util.AfterParentPostRunHook(util.ClientPostRunHooks),
}

cmd.AddCommand(NewDescribeCmd())
Expand Down
14 changes: 9 additions & 5 deletions cmd/cli/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,12 @@ func NewRootCmd() *cobra.Command {
"logging": configflags.LogFlags,
}
RootCmd := &cobra.Command{
Use: os.Args[0],
Short: "Compute over data",
Long: `Compute over data`,
PersistentPreRun: func(cmd *cobra.Command, args []string) {
Use: os.Args[0],
Short: "Compute over data",
Long: `Compute over data`,
PreRun: util.StartUpdateCheck,
PostRun: util.PrintUpdateCheck,
PersistentPreRunE: func(cmd *cobra.Command, args []string) error {
repoDir, err := config.Get[string]("repo")
if err != nil {
util.Fatal(cmd, fmt.Errorf("failed to read --repo value: %w", err), 1)
Expand Down Expand Up @@ -82,11 +84,13 @@ func NewRootCmd() *cobra.Command {
ctx = context.WithValue(ctx, spanKey, span)

cmd.SetContext(ctx)
return nil
},
PersistentPostRun: func(cmd *cobra.Command, args []string) {
PersistentPostRunE: func(cmd *cobra.Command, args []string) error {
ctx := cmd.Context()
ctx.Value(spanKey).(trace.Span).End()
ctx.Value(util.SystemManagerKey).(*system.CleanupManager).Cleanup(ctx)
return nil
},
}
// ensure the `repo` key always gets a usable default value, warn if it's not.
Expand Down
Loading