Skip to content

Commit 9a509bc

Browse files
authored
refactor(serverless_jobs): returns a list of job runs when starting a job definition (#436)
1 parent e90bd00 commit 9a509bc

File tree

8 files changed

+60
-6
lines changed

8 files changed

+60
-6
lines changed

scaleway-async/scaleway_async/jobs/v1alpha1/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
from .types import JobRun
1010
from .types import ListJobDefinitionsResponse
1111
from .types import ListJobRunsResponse
12+
from .types import StartJobDefinitionResponse
1213
from .types import UpdateJobDefinitionRequestCronScheduleConfig
1314
from .content import JOB_RUN_TRANSIENT_STATUSES
1415
from .api import JobsV1Alpha1API
@@ -23,6 +24,7 @@
2324
"JobRun",
2425
"ListJobDefinitionsResponse",
2526
"ListJobRunsResponse",
27+
"StartJobDefinitionResponse",
2628
"UpdateJobDefinitionRequestCronScheduleConfig",
2729
"JOB_RUN_TRANSIENT_STATUSES",
2830
"JobsV1Alpha1API",

scaleway-async/scaleway_async/jobs/v1alpha1/api.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
JobRun,
2121
ListJobDefinitionsResponse,
2222
ListJobRunsResponse,
23+
StartJobDefinitionResponse,
2324
UpdateJobDefinitionRequestCronScheduleConfig,
2425
CreateJobDefinitionRequest,
2526
UpdateJobDefinitionRequest,
@@ -33,6 +34,7 @@
3334
unmarshal_JobRun,
3435
unmarshal_ListJobDefinitionsResponse,
3536
unmarshal_ListJobRunsResponse,
37+
unmarshal_StartJobDefinitionResponse,
3638
)
3739

3840

@@ -332,7 +334,7 @@ async def start_job_definition(
332334
command: Optional[str] = None,
333335
environment_variables: Optional[Dict[str, str]] = None,
334336
replicas: Optional[int] = None,
335-
) -> JobRun:
337+
) -> StartJobDefinitionResponse:
336338
"""
337339
Run an existing job definition by its unique identifier. This will create a new job run.
338340
:param region: Region to target. If none is passed will use default region from the config.
@@ -344,7 +346,7 @@ async def start_job_definition(
344346
:param replicas: Number of jobs to run.
345347
346348
One-of ('_replicas'): at most one of 'replicas' could be set.
347-
:return: :class:`JobRun <JobRun>`
349+
:return: :class:`StartJobDefinitionResponse <StartJobDefinitionResponse>`
348350
349351
Usage:
350352
::
@@ -375,7 +377,7 @@ async def start_job_definition(
375377
)
376378

377379
self._throw_on_error(res)
378-
return unmarshal_JobRun(res.json())
380+
return unmarshal_StartJobDefinitionResponse(res.json())
379381

380382
async def get_job_run(
381383
self,

scaleway-async/scaleway_async/jobs/v1alpha1/marshalling.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
JobRun,
1717
ListJobDefinitionsResponse,
1818
ListJobRunsResponse,
19+
StartJobDefinitionResponse,
1920
UpdateJobDefinitionRequestCronScheduleConfig,
2021
CreateJobDefinitionRequest,
2122
UpdateJobDefinitionRequest,
@@ -184,6 +185,22 @@ def unmarshal_ListJobRunsResponse(data: Any) -> ListJobRunsResponse:
184185
return ListJobRunsResponse(**args)
185186

186187

188+
def unmarshal_StartJobDefinitionResponse(data: Any) -> StartJobDefinitionResponse:
189+
if type(data) is not dict:
190+
raise TypeError(
191+
f"Unmarshalling the type 'StartJobDefinitionResponse' failed as data isn't a dictionary."
192+
)
193+
194+
args: Dict[str, Any] = {}
195+
196+
field = data.get("job_runs", None)
197+
args["job_runs"] = (
198+
[unmarshal_JobRun(v) for v in field] if field is not None else None
199+
)
200+
201+
return StartJobDefinitionResponse(**args)
202+
203+
187204
def marshal_CreateJobDefinitionRequestCronScheduleConfig(
188205
request: CreateJobDefinitionRequestCronScheduleConfig,
189206
defaults: ProfileDefaults,

scaleway-async/scaleway_async/jobs/v1alpha1/types.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ class JobRunState(str, Enum, metaclass=StrEnumMeta):
2323
SUCCEEDED = "succeeded"
2424
FAILED = "failed"
2525
CANCELED = "canceled"
26+
INTERNAL_ERROR = "internal_error"
2627

2728
def __str__(self) -> str:
2829
return str(self.value)
@@ -138,6 +139,11 @@ class ListJobRunsResponse:
138139
total_count: int
139140

140141

142+
@dataclass
143+
class StartJobDefinitionResponse:
144+
job_runs: List[JobRun]
145+
146+
141147
@dataclass
142148
class UpdateJobDefinitionRequestCronScheduleConfig:
143149
schedule: Optional[str]

scaleway/scaleway/jobs/v1alpha1/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
from .types import JobRun
1010
from .types import ListJobDefinitionsResponse
1111
from .types import ListJobRunsResponse
12+
from .types import StartJobDefinitionResponse
1213
from .types import UpdateJobDefinitionRequestCronScheduleConfig
1314
from .content import JOB_RUN_TRANSIENT_STATUSES
1415
from .api import JobsV1Alpha1API
@@ -23,6 +24,7 @@
2324
"JobRun",
2425
"ListJobDefinitionsResponse",
2526
"ListJobRunsResponse",
27+
"StartJobDefinitionResponse",
2628
"UpdateJobDefinitionRequestCronScheduleConfig",
2729
"JOB_RUN_TRANSIENT_STATUSES",
2830
"JobsV1Alpha1API",

scaleway/scaleway/jobs/v1alpha1/api.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
JobRun,
2121
ListJobDefinitionsResponse,
2222
ListJobRunsResponse,
23+
StartJobDefinitionResponse,
2324
UpdateJobDefinitionRequestCronScheduleConfig,
2425
CreateJobDefinitionRequest,
2526
UpdateJobDefinitionRequest,
@@ -33,6 +34,7 @@
3334
unmarshal_JobRun,
3435
unmarshal_ListJobDefinitionsResponse,
3536
unmarshal_ListJobRunsResponse,
37+
unmarshal_StartJobDefinitionResponse,
3638
)
3739

3840

@@ -332,7 +334,7 @@ def start_job_definition(
332334
command: Optional[str] = None,
333335
environment_variables: Optional[Dict[str, str]] = None,
334336
replicas: Optional[int] = None,
335-
) -> JobRun:
337+
) -> StartJobDefinitionResponse:
336338
"""
337339
Run an existing job definition by its unique identifier. This will create a new job run.
338340
:param region: Region to target. If none is passed will use default region from the config.
@@ -344,7 +346,7 @@ def start_job_definition(
344346
:param replicas: Number of jobs to run.
345347
346348
One-of ('_replicas'): at most one of 'replicas' could be set.
347-
:return: :class:`JobRun <JobRun>`
349+
:return: :class:`StartJobDefinitionResponse <StartJobDefinitionResponse>`
348350
349351
Usage:
350352
::
@@ -375,7 +377,7 @@ def start_job_definition(
375377
)
376378

377379
self._throw_on_error(res)
378-
return unmarshal_JobRun(res.json())
380+
return unmarshal_StartJobDefinitionResponse(res.json())
379381

380382
def get_job_run(
381383
self,

scaleway/scaleway/jobs/v1alpha1/marshalling.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
JobRun,
1717
ListJobDefinitionsResponse,
1818
ListJobRunsResponse,
19+
StartJobDefinitionResponse,
1920
UpdateJobDefinitionRequestCronScheduleConfig,
2021
CreateJobDefinitionRequest,
2122
UpdateJobDefinitionRequest,
@@ -184,6 +185,22 @@ def unmarshal_ListJobRunsResponse(data: Any) -> ListJobRunsResponse:
184185
return ListJobRunsResponse(**args)
185186

186187

188+
def unmarshal_StartJobDefinitionResponse(data: Any) -> StartJobDefinitionResponse:
189+
if type(data) is not dict:
190+
raise TypeError(
191+
f"Unmarshalling the type 'StartJobDefinitionResponse' failed as data isn't a dictionary."
192+
)
193+
194+
args: Dict[str, Any] = {}
195+
196+
field = data.get("job_runs", None)
197+
args["job_runs"] = (
198+
[unmarshal_JobRun(v) for v in field] if field is not None else None
199+
)
200+
201+
return StartJobDefinitionResponse(**args)
202+
203+
187204
def marshal_CreateJobDefinitionRequestCronScheduleConfig(
188205
request: CreateJobDefinitionRequestCronScheduleConfig,
189206
defaults: ProfileDefaults,

scaleway/scaleway/jobs/v1alpha1/types.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ class JobRunState(str, Enum, metaclass=StrEnumMeta):
2323
SUCCEEDED = "succeeded"
2424
FAILED = "failed"
2525
CANCELED = "canceled"
26+
INTERNAL_ERROR = "internal_error"
2627

2728
def __str__(self) -> str:
2829
return str(self.value)
@@ -138,6 +139,11 @@ class ListJobRunsResponse:
138139
total_count: int
139140

140141

142+
@dataclass
143+
class StartJobDefinitionResponse:
144+
job_runs: List[JobRun]
145+
146+
141147
@dataclass
142148
class UpdateJobDefinitionRequestCronScheduleConfig:
143149
schedule: Optional[str]

0 commit comments

Comments
 (0)