Skip to content

Commit

Permalink
refactor(serverless_jobs): returns a list of job runs when starting a…
Browse files Browse the repository at this point in the history
… job definition (#1997)

Co-authored-by: Mia-Cross <[email protected]>
  • Loading branch information
scaleway-bot and Mia-Cross authored Feb 13, 2024
1 parent 7997819 commit 844b67c
Showing 1 changed file with 15 additions and 9 deletions.
24 changes: 15 additions & 9 deletions api/jobs/v1alpha1/jobs_sdk.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,14 @@ var (
type JobRunState string

const (
JobRunStateUnknownState = JobRunState("unknown_state")
JobRunStateQueued = JobRunState("queued")
JobRunStateScheduled = JobRunState("scheduled")
JobRunStateRunning = JobRunState("running")
JobRunStateSucceeded = JobRunState("succeeded")
JobRunStateFailed = JobRunState("failed")
JobRunStateCanceled = JobRunState("canceled")
JobRunStateUnknownState = JobRunState("unknown_state")
JobRunStateQueued = JobRunState("queued")
JobRunStateScheduled = JobRunState("scheduled")
JobRunStateRunning = JobRunState("running")
JobRunStateSucceeded = JobRunState("succeeded")
JobRunStateFailed = JobRunState("failed")
JobRunStateCanceled = JobRunState("canceled")
JobRunStateInternalError = JobRunState("internal_error")
)

func (enum JobRunState) String() string {
Expand Down Expand Up @@ -384,6 +385,11 @@ type StartJobDefinitionRequest struct {
Replicas *uint32 `json:"replicas,omitempty"`
}

// StartJobDefinitionResponse: start job definition response.
type StartJobDefinitionResponse struct {
JobRuns []*JobRun `json:"job_runs"`
}

// StopJobRunRequest: stop job run request.
type StopJobRunRequest struct {
// Region: region to target. If none is passed will use default region from the config.
Expand Down Expand Up @@ -620,7 +626,7 @@ func (s *API) DeleteJobDefinition(req *DeleteJobDefinitionRequest, opts ...scw.R
}

// StartJobDefinition: Run an existing job definition by its unique identifier. This will create a new job run.
func (s *API) StartJobDefinition(req *StartJobDefinitionRequest, opts ...scw.RequestOption) (*JobRun, error) {
func (s *API) StartJobDefinition(req *StartJobDefinitionRequest, opts ...scw.RequestOption) (*StartJobDefinitionResponse, error) {
var err error

if req.Region == "" {
Expand All @@ -646,7 +652,7 @@ func (s *API) StartJobDefinition(req *StartJobDefinitionRequest, opts ...scw.Req
return nil, err
}

var resp JobRun
var resp StartJobDefinitionResponse

err = s.client.Do(scwReq, &resp, opts...)
if err != nil {
Expand Down

0 comments on commit 844b67c

Please sign in to comment.