Skip to content

Commit 3ad4a0c

Browse files
Guillaume NoaleGnoale
Guillaume Noale
andauthored
fix(jobs): panic when starting a job with --wait (#4665)
Co-authored-by: Guillaume Noale <[email protected]>
1 parent 416f7ea commit 3ad4a0c

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

internal/namespaces/jobs/v1alpha1/custom_job_definition.go

+7-2
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package jobs
22

33
import (
44
"context"
5+
"errors"
56
"fmt"
67

78
"github.com/scaleway/scaleway-cli/v2/core"
@@ -14,7 +15,7 @@ func definitionStartBuilder(c *core.Command) *core.Command {
1415
c.WaitFunc = func(ctx context.Context, argsI, respI interface{}) (interface{}, error) {
1516
api := jobs.NewAPI(core.ExtractClient(ctx))
1617
args := argsI.(*jobs.StartJobDefinitionRequest)
17-
resp := respI.(*jobs.JobRun)
18+
resp := respI.(*jobs.StartJobDefinitionResponse)
1819

1920
jobDefinition, err := api.GetJobDefinition(&jobs.GetJobDefinitionRequest{
2021
Region: args.Region,
@@ -24,9 +25,13 @@ func definitionStartBuilder(c *core.Command) *core.Command {
2425
return nil, fmt.Errorf("failed to fetch job definition for timeout: %w", err)
2526
}
2627

28+
if len(resp.JobRuns) == 0 {
29+
return nil, errors.New("no job run found")
30+
}
31+
2732
return api.WaitForJobRun(&jobs.WaitForJobRunRequest{
2833
Region: args.Region,
29-
JobRunID: resp.ID,
34+
JobRunID: resp.JobRuns[0].ID,
3035
Timeout: jobDefinition.JobTimeout.ToTimeDuration(),
3136
RetryInterval: core.DefaultRetryInterval,
3237
})

0 commit comments

Comments
 (0)