Skip to content

Commit

Permalink
feat: cancellable jobs commands
Browse files Browse the repository at this point in the history
  • Loading branch information
alexplischke committed Dec 10, 2024
1 parent feb7b11 commit 22572c1
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
8 changes: 4 additions & 4 deletions internal/cmd/jobs/get.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,11 @@ func GetCommand() *cobra.Command {
_ = tracker.Close()
}()
},
RunE: func(_ *cobra.Command, args []string) error {
RunE: func(cmd *cobra.Command, args []string) error {
if out != JSONOutput && out != TextOutput {
return errors.New("unknown output format")
}
return get(args[0], out)
return get(cmd.Context(), args[0], out)
},
}
flags := cmd.PersistentFlags()
Expand All @@ -49,8 +49,8 @@ func GetCommand() *cobra.Command {
return cmd
}

func get(jobID, outputFormat string) error {
j, err := jobService.ReadJob(context.Background(), jobID)
func get(ctx context.Context, jobID, outputFormat string) error {
j, err := jobService.ReadJob(ctx, jobID)
if err != nil {
return fmt.Errorf("failed to get job: %w", err)
}
Expand Down
10 changes: 5 additions & 5 deletions internal/cmd/jobs/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ func ListCommand() *cobra.Command {
_ = tracker.Close()
}()
},
RunE: func(_ *cobra.Command, _ []string) error {
RunE: func(cmd *cobra.Command, _ []string) error {
if page < 0 {
return errors.New("invalid page")
}
Expand All @@ -112,7 +112,7 @@ func ListCommand() *cobra.Command {
return errors.New("invalid job resource. Options: vdc, rdc, api")
}

return list(out, page, size, status, job.Source(jobSource))
return list(cmd.Context(), out, page, size, status, job.Source(jobSource))
},
}
flags := cmd.PersistentFlags()
Expand All @@ -125,8 +125,8 @@ func ListCommand() *cobra.Command {
return cmd
}

func list(format string, page int, size int, status string, source job.Source) error {
user, err := userService.User(context.Background())
func list(ctx context.Context, format string, page int, size int, status string, source job.Source) error {
user, err := userService.User(ctx)
if err != nil {
return fmt.Errorf("failed to get user: %w", err)
}
Expand All @@ -139,7 +139,7 @@ func list(format string, page int, size int, status string, source job.Source) e
Source: source,
}

jobs, err := jobService.ListJobs(context.Background(), opts)
jobs, err := jobService.ListJobs(ctx, opts)
if err != nil {
return fmt.Errorf("failed to get jobs: %w", err)
}
Expand Down

0 comments on commit 22572c1

Please sign in to comment.