Skip to content

Commit 566a38e

Browse files
authored
feat(serverless_jobs): add ListJobsResources method (#1309)
1 parent b71a504 commit 566a38e

File tree

4 files changed

+67
-0
lines changed

4 files changed

+67
-0
lines changed

packages/clients/src/api/jobs/v1alpha1/api.gen.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import {
1515
unmarshalJobRun,
1616
unmarshalListJobDefinitionsResponse,
1717
unmarshalListJobRunsResponse,
18+
unmarshalListJobsResourcesResponse,
1819
unmarshalStartJobDefinitionResponse,
1920
} from './marshalling.gen'
2021
import type {
@@ -28,6 +29,8 @@ import type {
2829
ListJobDefinitionsResponse,
2930
ListJobRunsRequest,
3031
ListJobRunsResponse,
32+
ListJobsResourcesRequest,
33+
ListJobsResourcesResponse,
3134
StartJobDefinitionRequest,
3235
StartJobDefinitionResponse,
3336
StopJobRunRequest,
@@ -226,4 +229,19 @@ export class API extends ParentAPI {
226229
*/
227230
listJobRuns = (request: Readonly<ListJobRunsRequest> = {}) =>
228231
enrichForPagination('jobRuns', this.pageOfListJobRuns, request)
232+
233+
/**
234+
* List jobs resources for the console.
235+
*
236+
* @param request - The request {@link ListJobsResourcesRequest}
237+
* @returns A Promise of ListJobsResourcesResponse
238+
*/
239+
listJobsResources = (request: Readonly<ListJobsResourcesRequest> = {}) =>
240+
this.client.fetch<ListJobsResourcesResponse>(
241+
{
242+
method: 'GET',
243+
path: `/serverless-jobs/v1alpha1/regions/${validatePathParam('region', request.region ?? this.client.settings.defaultRegion)}/jobs-resources`,
244+
},
245+
unmarshalListJobsResourcesResponse,
246+
)
229247
}

packages/clients/src/api/jobs/v1alpha1/index.gen.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@ export type {
1818
ListJobRunsRequest,
1919
ListJobRunsRequestOrderBy,
2020
ListJobRunsResponse,
21+
ListJobsResourcesRequest,
22+
ListJobsResourcesResponse,
23+
Resource,
2124
StartJobDefinitionRequest,
2225
StartJobDefinitionResponse,
2326
StopJobRunRequest,

packages/clients/src/api/jobs/v1alpha1/marshalling.gen.ts

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ import type {
1515
JobRun,
1616
ListJobDefinitionsResponse,
1717
ListJobRunsResponse,
18+
ListJobsResourcesResponse,
19+
Resource,
1820
StartJobDefinitionRequest,
1921
StartJobDefinitionResponse,
2022
UpdateJobDefinitionRequest,
@@ -122,6 +124,33 @@ export const unmarshalListJobRunsResponse = (
122124
} as ListJobRunsResponse
123125
}
124126

127+
const unmarshalResource = (data: unknown): Resource => {
128+
if (!isJSONObject(data)) {
129+
throw new TypeError(
130+
`Unmarshalling the type 'Resource' failed as data isn't a dictionary.`,
131+
)
132+
}
133+
134+
return {
135+
cpuLimit: data.cpu_limit,
136+
memoryLimit: data.memory_limit,
137+
} as Resource
138+
}
139+
140+
export const unmarshalListJobsResourcesResponse = (
141+
data: unknown,
142+
): ListJobsResourcesResponse => {
143+
if (!isJSONObject(data)) {
144+
throw new TypeError(
145+
`Unmarshalling the type 'ListJobsResourcesResponse' failed as data isn't a dictionary.`,
146+
)
147+
}
148+
149+
return {
150+
resources: unmarshalArrayOfObject(data.resources, unmarshalResource),
151+
} as ListJobsResourcesResponse
152+
}
153+
125154
export const unmarshalStartJobDefinitionResponse = (
126155
data: unknown,
127156
): StartJobDefinitionResponse => {

packages/clients/src/api/jobs/v1alpha1/types.gen.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,11 @@ export interface JobRun {
7878
region: Region
7979
}
8080

81+
export interface Resource {
82+
cpuLimit: number
83+
memoryLimit: number
84+
}
85+
8186
export interface UpdateJobDefinitionRequestCronScheduleConfig {
8287
schedule?: string
8388
timezone?: string
@@ -182,6 +187,18 @@ export interface ListJobRunsResponse {
182187
totalCount: number
183188
}
184189

190+
export type ListJobsResourcesRequest = {
191+
/**
192+
* Region to target. If none is passed will use default region from the
193+
* config.
194+
*/
195+
region?: Region
196+
}
197+
198+
export interface ListJobsResourcesResponse {
199+
resources: Resource[]
200+
}
201+
185202
export type StartJobDefinitionRequest = {
186203
/**
187204
* Region to target. If none is passed will use default region from the

0 commit comments

Comments
 (0)