Skip to content

Commit 0900a76

Browse files
authored
feat(serverless): add CronSchedule to job definitions (#1074)
1 parent ab7c1c8 commit 0900a76

File tree

4 files changed

+103
-0
lines changed

4 files changed

+103
-0
lines changed

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ export { API } from './api.gen'
44
export * from './content.gen'
55
export type {
66
CreateJobDefinitionRequest,
7+
CreateJobDefinitionRequestCronScheduleConfig,
8+
CronSchedule,
79
DeleteJobDefinitionRequest,
810
GetJobDefinitionRequest,
911
GetJobRunRequest,
@@ -19,5 +21,6 @@ export type {
1921
StartJobDefinitionRequest,
2022
StopJobRunRequest,
2123
UpdateJobDefinitionRequest,
24+
UpdateJobDefinitionRequestCronScheduleConfig,
2225
} from './types.gen'
2326
export * as ValidationRules from './validation-rules.gen'

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

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,29 @@ import {
99
import type { DefaultValues } from '../../../bridge'
1010
import type {
1111
CreateJobDefinitionRequest,
12+
CreateJobDefinitionRequestCronScheduleConfig,
13+
CronSchedule,
1214
JobDefinition,
1315
JobRun,
1416
ListJobDefinitionsResponse,
1517
ListJobRunsResponse,
1618
UpdateJobDefinitionRequest,
19+
UpdateJobDefinitionRequestCronScheduleConfig,
1720
} from './types.gen'
1821

22+
const unmarshalCronSchedule = (data: unknown): CronSchedule => {
23+
if (!isJSONObject(data)) {
24+
throw new TypeError(
25+
`Unmarshalling the type 'CronSchedule' failed as data isn't a dictionary.`,
26+
)
27+
}
28+
29+
return {
30+
schedule: data.schedule,
31+
timezone: data.timezone,
32+
} as CronSchedule
33+
}
34+
1935
export const unmarshalJobDefinition = (data: unknown): JobDefinition => {
2036
if (!isJSONObject(data)) {
2137
throw new TypeError(
@@ -27,6 +43,9 @@ export const unmarshalJobDefinition = (data: unknown): JobDefinition => {
2743
command: data.command,
2844
cpuLimit: data.cpu_limit,
2945
createdAt: unmarshalDate(data.created_at),
46+
cronSchedule: data.cron_schedule
47+
? unmarshalCronSchedule(data.cron_schedule)
48+
: undefined,
3049
description: data.description,
3150
environmentVariables: data.environment_variables,
3251
id: data.id,
@@ -96,12 +115,27 @@ export const unmarshalListJobRunsResponse = (
96115
} as ListJobRunsResponse
97116
}
98117

118+
const marshalCreateJobDefinitionRequestCronScheduleConfig = (
119+
request: CreateJobDefinitionRequestCronScheduleConfig,
120+
defaults: DefaultValues,
121+
): Record<string, unknown> => ({
122+
schedule: request.schedule,
123+
timezone: request.timezone,
124+
})
125+
99126
export const marshalCreateJobDefinitionRequest = (
100127
request: CreateJobDefinitionRequest,
101128
defaults: DefaultValues,
102129
): Record<string, unknown> => ({
103130
command: request.command,
104131
cpu_limit: request.cpuLimit,
132+
cron_schedule:
133+
request.cronSchedule !== undefined
134+
? marshalCreateJobDefinitionRequestCronScheduleConfig(
135+
request.cronSchedule,
136+
defaults,
137+
)
138+
: undefined,
105139
description: request.description,
106140
environment_variables:
107141
request.environmentVariables !== undefined
@@ -114,12 +148,27 @@ export const marshalCreateJobDefinitionRequest = (
114148
project_id: request.projectId ?? defaults.defaultProjectId,
115149
})
116150

151+
const marshalUpdateJobDefinitionRequestCronScheduleConfig = (
152+
request: UpdateJobDefinitionRequestCronScheduleConfig,
153+
defaults: DefaultValues,
154+
): Record<string, unknown> => ({
155+
schedule: request.schedule,
156+
timezone: request.timezone,
157+
})
158+
117159
export const marshalUpdateJobDefinitionRequest = (
118160
request: UpdateJobDefinitionRequest,
119161
defaults: DefaultValues,
120162
): Record<string, unknown> => ({
121163
command: request.command,
122164
cpu_limit: request.cpuLimit,
165+
cron_schedule:
166+
request.cronSchedule !== undefined
167+
? marshalUpdateJobDefinitionRequestCronScheduleConfig(
168+
request.cronSchedule,
169+
defaults,
170+
)
171+
: undefined,
123172
description: request.description,
124173
environment_variables: request.environmentVariables,
125174
image_uri: request.imageUri,

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

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,16 @@ export type ListJobDefinitionsRequestOrderBy =
1717

1818
export type ListJobRunsRequestOrderBy = 'created_at_asc' | 'created_at_desc'
1919

20+
export interface CronSchedule {
21+
schedule: string
22+
timezone: string
23+
}
24+
25+
export interface CreateJobDefinitionRequestCronScheduleConfig {
26+
schedule: string
27+
timezone: string
28+
}
29+
2030
export interface JobDefinition {
2131
id: string
2232
name: string
@@ -30,6 +40,7 @@ export interface JobDefinition {
3040
environmentVariables: Record<string, string>
3141
description: string
3242
jobTimeout?: string
43+
cronSchedule?: CronSchedule
3344
/**
3445
* Region to target. If none is passed will use default region from the
3546
* config.
@@ -56,6 +67,11 @@ export interface JobRun {
5667
region: Region
5768
}
5869

70+
export interface UpdateJobDefinitionRequestCronScheduleConfig {
71+
schedule?: string
72+
timezone?: string
73+
}
74+
5975
export type CreateJobDefinitionRequest = {
6076
/**
6177
* Region to target. If none is passed will use default region from the
@@ -80,6 +96,7 @@ export type CreateJobDefinitionRequest = {
8096
description: string
8197
/** Timeout of the job in seconds. */
8298
jobTimeout?: string
99+
cronSchedule?: CreateJobDefinitionRequestCronScheduleConfig
83100
}
84101

85102
export type DeleteJobDefinitionRequest = {
@@ -191,4 +208,5 @@ export type UpdateJobDefinitionRequest = {
191208
description?: string
192209
/** Timeout of the job in seconds. */
193210
jobTimeout?: string
211+
cronSchedule?: UpdateJobDefinitionRequestCronScheduleConfig
194212
}

packages/clients/src/api/jobs/v1alpha1/validation-rules.gen.ts

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,28 @@ export const CreateJobDefinitionRequest = {
1717
},
1818
}
1919

20+
export const CreateJobDefinitionRequestCronScheduleConfig = {
21+
schedule: {
22+
maxLength: 255,
23+
minLength: 1,
24+
},
25+
timezone: {
26+
maxLength: 255,
27+
minLength: 1,
28+
},
29+
}
30+
31+
export const CronSchedule = {
32+
schedule: {
33+
maxLength: 255,
34+
minLength: 1,
35+
},
36+
timezone: {
37+
maxLength: 255,
38+
minLength: 1,
39+
},
40+
}
41+
2042
export const ListJobDefinitionsRequest = {
2143
page: {
2244
greaterThanOrEqual: 1,
@@ -52,3 +74,14 @@ export const UpdateJobDefinitionRequest = {
5274
pattern: /^[A-Za-z0-9-_]{3,50}$/,
5375
},
5476
}
77+
78+
export const UpdateJobDefinitionRequestCronScheduleConfig = {
79+
schedule: {
80+
maxLength: 255,
81+
minLength: 1,
82+
},
83+
timezone: {
84+
maxLength: 255,
85+
minLength: 1,
86+
},
87+
}

0 commit comments

Comments
 (0)