Skip to content

Commit

Permalink
feat: cancellable project uploads and job commands (#990)
Browse files Browse the repository at this point in the history
* feat: cancellable project upload

* feat: cancellable jobs commands
  • Loading branch information
alexplischke authored Dec 10, 2024
1 parent 1340597 commit f443c9f
Show file tree
Hide file tree
Showing 27 changed files with 120 additions and 106 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
2 changes: 1 addition & 1 deletion internal/cmd/run/cucumber.go
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ func runCucumber(cmd *cobra.Command, isCLIDriven bool) (int, error) {
}

p.Npm.Packages = cleanPlaywrightPackages(p.Npm, p.Playwright.Version)
return r.RunProject()
return r.RunProject(cmd.Context())
}

func applyCucumberFlags(p *cucumber.Project) error {
Expand Down
2 changes: 1 addition & 1 deletion internal/cmd/run/cypress.go
Original file line number Diff line number Diff line change
Expand Up @@ -200,5 +200,5 @@ func runCypress(cmd *cobra.Command, cflags cypressFlags, isCLIDriven bool) (int,
}

p.CleanPackages()
return r.RunProject()
return r.RunProject(cmd.Context())
}
7 changes: 4 additions & 3 deletions internal/cmd/run/espresso.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package run

import (
"context"
"os"

cmds "github.com/saucelabs/saucectl/internal/cmd"
Expand Down Expand Up @@ -130,10 +131,10 @@ func runEspresso(cmd *cobra.Command, espressoFlags espressoFlags, isCLIDriven bo

cleanupArtifacts(p.Artifacts)

return runEspressoInCloud(p, regio)
return runEspressoInCloud(cmd.Context(), p, regio)
}

func runEspressoInCloud(p espresso.Project, regio region.Region) (int, error) {
func runEspressoInCloud(ctx context.Context, p espresso.Project, regio region.Region) (int, error) {
log.Info().
Str("region", regio.String()).
Str("tunnel", p.Sauce.Tunnel.Name).
Expand Down Expand Up @@ -180,7 +181,7 @@ func runEspressoInCloud(p espresso.Project, regio region.Region) (int, error) {
},
}

return r.RunProject()
return r.RunProject(ctx)
}

func hasKey(testOptions map[string]interface{}, key string) bool {
Expand Down
2 changes: 1 addition & 1 deletion internal/cmd/run/playwright.go
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ func runPlaywright(cmd *cobra.Command, pf playwrightFlags, isCLIDriven bool) (in
}

p.Npm.Packages = cleanPlaywrightPackages(p.Npm, p.Playwright.Version)
return r.RunProject()
return r.RunProject(cmd.Context())
}

func applyPlaywrightFlags(p *playwright.Project) error {
Expand Down
7 changes: 4 additions & 3 deletions internal/cmd/run/replay.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package run

import (
"context"
"errors"
"os"

Expand Down Expand Up @@ -116,10 +117,10 @@ func runReplay(cmd *cobra.Command, isCLIDriven bool) (int, error) {

cleanupArtifacts(p.Artifacts)

return runPuppeteerReplayInSauce(p, regio)
return runPuppeteerReplayInSauce(cmd.Context(), p, regio)
}

func runPuppeteerReplayInSauce(p replay.Project, regio region.Region) (int, error) {
func runPuppeteerReplayInSauce(ctx context.Context, p replay.Project, regio region.Region) (int, error) {
log.Info().
Str("region", regio.String()).
Str("tunnel", p.Sauce.Tunnel.Name).
Expand Down Expand Up @@ -163,7 +164,7 @@ func runPuppeteerReplayInSauce(p replay.Project, regio region.Region) (int, erro
},
}

return r.RunProject()
return r.RunProject(ctx)
}

func applyPuppeteerReplayFlags(p *replay.Project) error {
Expand Down
2 changes: 1 addition & 1 deletion internal/cmd/run/testcafe.go
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ func runTestcafe(cmd *cobra.Command, tcFlags testcafeFlags, isCLIDriven bool) (i
}

cleanTestCafePackages(&p)
return r.RunProject()
return r.RunProject(cmd.Context())
}

func applyTestcafeFlags(p *testcafe.Project, flags testcafeFlags) error {
Expand Down
7 changes: 4 additions & 3 deletions internal/cmd/run/xcuitest.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package run

import (
"context"
"os"

cmds "github.com/saucelabs/saucectl/internal/cmd"
Expand Down Expand Up @@ -130,10 +131,10 @@ func runXcuitest(cmd *cobra.Command, xcuiFlags xcuitestFlags, isCLIDriven bool)

cleanupArtifacts(p.Artifacts)

return runXcuitestInCloud(p, regio)
return runXcuitestInCloud(cmd.Context(), p, regio)
}

func runXcuitestInCloud(p xcuitest.Project, regio region.Region) (int, error) {
func runXcuitestInCloud(ctx context.Context, p xcuitest.Project, regio region.Region) (int, error) {
log.Info().
Str("region", regio.String()).
Str("tunnel", p.Sauce.Tunnel.Name).
Expand Down Expand Up @@ -180,7 +181,7 @@ func runXcuitestInCloud(p xcuitest.Project, regio region.Region) (int, error) {
},
},
}
return r.RunProject()
return r.RunProject(ctx)
}

func applyXCUITestFlags(p *xcuitest.Project, flags xcuitestFlags) error {
Expand Down
6 changes: 3 additions & 3 deletions internal/http/rdcservice_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -493,7 +493,7 @@ func TestRDCService_StartJob(t *testing.T) {
{
name: "Happy path",
args: args{
ctx: context.TODO(),
ctx: context.Background(),
jobStarterPayload: job.StartOptions{
User: "fake-user",
AccessKey: "fake-access-key",
Expand All @@ -519,7 +519,7 @@ func TestRDCService_StartJob(t *testing.T) {
{
name: "Non 2xx status code",
args: args{
ctx: context.TODO(),
ctx: context.Background(),
jobStarterPayload: job.StartOptions{},
},
want: job.Job{},
Expand All @@ -531,7 +531,7 @@ func TestRDCService_StartJob(t *testing.T) {
{
name: "Unknown error",
args: args{
ctx: context.TODO(),
ctx: context.Background(),
jobStarterPayload: job.StartOptions{},
},
want: job.Job{},
Expand Down
6 changes: 3 additions & 3 deletions internal/http/webdriver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ func TestWebdriver_StartJob(t *testing.T) {
{
name: "Happy path",
args: args{
ctx: context.TODO(),
ctx: context.Background(),
jobStarterPayload: job.StartOptions{
User: "fake-user",
AccessKey: "fake-access-key",
Expand All @@ -61,7 +61,7 @@ func TestWebdriver_StartJob(t *testing.T) {
{
name: "Non 2xx status code",
args: args{
ctx: context.TODO(),
ctx: context.Background(),
jobStarterPayload: job.StartOptions{},
},
want: job.Job{},
Expand All @@ -74,7 +74,7 @@ func TestWebdriver_StartJob(t *testing.T) {
{
name: "Unknown error",
args: args{
ctx: context.TODO(),
ctx: context.Background(),
jobStarterPayload: job.StartOptions{},
},
want: job.Job{},
Expand Down
Loading

0 comments on commit f443c9f

Please sign in to comment.