Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 55 additions & 0 deletions packages/clients/src/api/jobs/v1alpha1/api.gen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,12 @@ export class API extends ParentAPI {
/** Lists the available regions of the API. */
public static readonly LOCALITIES: Region[] = ['fr-par', 'nl-ams', 'pl-waw']

/**
* Create a new job definition in a specified Project.
*
* @param request - The request {@link CreateJobDefinitionRequest}
* @returns A Promise of JobDefinition
*/
createJobDefinition = (request: Readonly<CreateJobDefinitionRequest>) =>
this.client.fetch<JobDefinition>(
{
Expand All @@ -56,6 +62,12 @@ export class API extends ParentAPI {
unmarshalJobDefinition,
)

/**
* Get a job definition by its unique identifier.
*
* @param request - The request {@link GetJobDefinitionRequest}
* @returns A Promise of JobDefinition
*/
getJobDefinition = (request: Readonly<GetJobDefinitionRequest>) =>
this.client.fetch<JobDefinition>(
{
Expand Down Expand Up @@ -94,13 +106,26 @@ export class API extends ParentAPI {
unmarshalListJobDefinitionsResponse,
)

/**
* List all your job definitions with filters.
*
* @param request - The request {@link ListJobDefinitionsRequest}
* @returns A Promise of ListJobDefinitionsResponse
*/
listJobDefinitions = (request: Readonly<ListJobDefinitionsRequest> = {}) =>
enrichForPagination(
'jobDefinitions',
this.pageOfListJobDefinitions,
request,
)

/**
* Update an existing job definition associated with the specified unique
* identifier.
*
* @param request - The request {@link UpdateJobDefinitionRequest}
* @returns A Promise of JobDefinition
*/
updateJobDefinition = (request: Readonly<UpdateJobDefinitionRequest>) =>
this.client.fetch<JobDefinition>(
{
Expand All @@ -120,6 +145,11 @@ export class API extends ParentAPI {
unmarshalJobDefinition,
)

/**
* Delete an exsisting job definition by its unique identifier.
*
* @param request - The request {@link DeleteJobDefinitionRequest}
*/
deleteJobDefinition = (request: Readonly<DeleteJobDefinitionRequest>) =>
this.client.fetch<void>({
method: 'DELETE',
Expand All @@ -132,6 +162,13 @@ export class API extends ParentAPI {
)}`,
})

/**
* Run an existing job definition by its unique identifier. This will create a
* new job run.
*
* @param request - The request {@link StartJobDefinitionRequest}
* @returns A Promise of JobRun
*/
startJobDefinition = (request: Readonly<StartJobDefinitionRequest>) =>
this.client.fetch<JobRun>(
{
Expand All @@ -149,6 +186,12 @@ export class API extends ParentAPI {
unmarshalJobRun,
)

/**
* Get a job run by its unique identifier.
*
* @param request - The request {@link GetJobRunRequest}
* @returns A Promise of JobRun
*/
getJobRun = (request: Readonly<GetJobRunRequest>) =>
this.client.fetch<JobRun>(
{
Expand All @@ -161,6 +204,12 @@ export class API extends ParentAPI {
unmarshalJobRun,
)

/**
* Stop a job run by its unique identifier.
*
* @param request - The request {@link StopJobRunRequest}
* @returns A Promise of JobRun
*/
stopJobRun = (request: Readonly<StopJobRunRequest>) =>
this.client.fetch<JobRun>(
{
Expand Down Expand Up @@ -197,6 +246,12 @@ export class API extends ParentAPI {
unmarshalListJobRunsResponse,
)

/**
* List all job runs with filters.
*
* @param request - The request {@link ListJobRunsRequest}
* @returns A Promise of ListJobRunsResponse
*/
listJobRuns = (request: Readonly<ListJobRunsRequest> = {}) =>
enrichForPagination('jobRuns', this.pageOfListJobRuns, request)
}
3 changes: 3 additions & 0 deletions packages/clients/src/api/jobs/v1alpha1/index.gen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ export { API } from './api.gen'
export * from './content.gen'
export type {
CreateJobDefinitionRequest,
CreateJobDefinitionRequestCronScheduleConfig,
CronSchedule,
DeleteJobDefinitionRequest,
GetJobDefinitionRequest,
GetJobRunRequest,
Expand All @@ -19,5 +21,6 @@ export type {
StartJobDefinitionRequest,
StopJobRunRequest,
UpdateJobDefinitionRequest,
UpdateJobDefinitionRequestCronScheduleConfig,
} from './types.gen'
export * as ValidationRules from './validation-rules.gen'
49 changes: 49 additions & 0 deletions packages/clients/src/api/jobs/v1alpha1/marshalling.gen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,29 @@ import {
import type { DefaultValues } from '../../../bridge'
import type {
CreateJobDefinitionRequest,
CreateJobDefinitionRequestCronScheduleConfig,
CronSchedule,
JobDefinition,
JobRun,
ListJobDefinitionsResponse,
ListJobRunsResponse,
UpdateJobDefinitionRequest,
UpdateJobDefinitionRequestCronScheduleConfig,
} from './types.gen'

const unmarshalCronSchedule = (data: unknown): CronSchedule => {
if (!isJSONObject(data)) {
throw new TypeError(
`Unmarshalling the type 'CronSchedule' failed as data isn't a dictionary.`,
)
}

return {
schedule: data.schedule,
timezone: data.timezone,
} as CronSchedule
}

export const unmarshalJobDefinition = (data: unknown): JobDefinition => {
if (!isJSONObject(data)) {
throw new TypeError(
Expand All @@ -27,6 +43,9 @@ export const unmarshalJobDefinition = (data: unknown): JobDefinition => {
command: data.command,
cpuLimit: data.cpu_limit,
createdAt: unmarshalDate(data.created_at),
cronSchedule: data.cron_schedule
? unmarshalCronSchedule(data.cron_schedule)
: undefined,
description: data.description,
environmentVariables: data.environment_variables,
id: data.id,
Expand Down Expand Up @@ -96,12 +115,27 @@ export const unmarshalListJobRunsResponse = (
} as ListJobRunsResponse
}

const marshalCreateJobDefinitionRequestCronScheduleConfig = (
request: CreateJobDefinitionRequestCronScheduleConfig,
defaults: DefaultValues,
): Record<string, unknown> => ({
schedule: request.schedule,
timezone: request.timezone,
})

export const marshalCreateJobDefinitionRequest = (
request: CreateJobDefinitionRequest,
defaults: DefaultValues,
): Record<string, unknown> => ({
command: request.command,
cpu_limit: request.cpuLimit,
cron_schedule:
request.cronSchedule !== undefined
? marshalCreateJobDefinitionRequestCronScheduleConfig(
request.cronSchedule,
defaults,
)
: undefined,
description: request.description,
environment_variables:
request.environmentVariables !== undefined
Expand All @@ -114,12 +148,27 @@ export const marshalCreateJobDefinitionRequest = (
project_id: request.projectId ?? defaults.defaultProjectId,
})

const marshalUpdateJobDefinitionRequestCronScheduleConfig = (
request: UpdateJobDefinitionRequestCronScheduleConfig,
defaults: DefaultValues,
): Record<string, unknown> => ({
schedule: request.schedule,
timezone: request.timezone,
})

export const marshalUpdateJobDefinitionRequest = (
request: UpdateJobDefinitionRequest,
defaults: DefaultValues,
): Record<string, unknown> => ({
command: request.command,
cpu_limit: request.cpuLimit,
cron_schedule:
request.cronSchedule !== undefined
? marshalUpdateJobDefinitionRequestCronScheduleConfig(
request.cronSchedule,
defaults,
)
: undefined,
description: request.description,
environment_variables: request.environmentVariables,
image_uri: request.imageUri,
Expand Down
41 changes: 41 additions & 0 deletions packages/clients/src/api/jobs/v1alpha1/types.gen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,16 @@ export type ListJobDefinitionsRequestOrderBy =

export type ListJobRunsRequestOrderBy = 'created_at_asc' | 'created_at_desc'

export interface CronSchedule {
schedule: string
timezone: string
}

export interface CreateJobDefinitionRequestCronScheduleConfig {
schedule: string
timezone: string
}

export interface JobDefinition {
id: string
name: string
Expand All @@ -30,6 +40,7 @@ export interface JobDefinition {
environmentVariables: Record<string, string>
description: string
jobTimeout?: string
cronSchedule?: CronSchedule
/**
* Region to target. If none is passed will use default region from the
* config.
Expand All @@ -56,21 +67,36 @@ export interface JobRun {
region: Region
}

export interface UpdateJobDefinitionRequestCronScheduleConfig {
schedule?: string
timezone?: string
}

export type CreateJobDefinitionRequest = {
/**
* Region to target. If none is passed will use default region from the
* config.
*/
region?: Region
/** Name of the job definition. */
name?: string
/** CPU limit of the job. */
cpuLimit: number
/** Memory limit of the job. */
memoryLimit: number
/** Image to use for the job. */
imageUri: string
/** Startup command. */
command: string
/** UUID of the Scaleway Project containing the job. */
projectId?: string
/** Environment variables of the job. */
environmentVariables?: Record<string, string>
/** Description of the job. */
description: string
/** Timeout of the job in seconds. */
jobTimeout?: string
cronSchedule?: CreateJobDefinitionRequestCronScheduleConfig
}

export type DeleteJobDefinitionRequest = {
Expand All @@ -79,6 +105,7 @@ export type DeleteJobDefinitionRequest = {
* config.
*/
region?: Region
/** UUID of the job definition to delete. */
jobDefinitionId: string
}

Expand All @@ -88,6 +115,7 @@ export type GetJobDefinitionRequest = {
* config.
*/
region?: Region
/** UUID of the job definition to get. */
jobDefinitionId: string
}

Expand All @@ -97,6 +125,7 @@ export type GetJobRunRequest = {
* config.
*/
region?: Region
/** UUID of the job run to get. */
jobRunId: string
}

Expand Down Expand Up @@ -141,6 +170,7 @@ export type StartJobDefinitionRequest = {
* config.
*/
region?: Region
/** UUID of the job definition to start. */
jobDefinitionId: string
}

Expand All @@ -150,6 +180,7 @@ export type StopJobRunRequest = {
* config.
*/
region?: Region
/** UUID of the job run to stop. */
jobRunId: string
}

Expand All @@ -159,13 +190,23 @@ export type UpdateJobDefinitionRequest = {
* config.
*/
region?: Region
/** UUID of the job definition to update. */
jobDefinitionId: string
/** Name of the job definition. */
name?: string
/** CPU limit of the job. */
cpuLimit?: number
/** Memory limit of the job. */
memoryLimit?: number
/** Image to use for the job. */
imageUri?: string
/** Startup command. */
command?: string
/** Environment variables of the job. */
environmentVariables?: Record<string, string>
/** Description of the job. */
description?: string
/** Timeout of the job in seconds. */
jobTimeout?: string
cronSchedule?: UpdateJobDefinitionRequestCronScheduleConfig
}
33 changes: 33 additions & 0 deletions packages/clients/src/api/jobs/v1alpha1/validation-rules.gen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,28 @@ export const CreateJobDefinitionRequest = {
},
}

export const CreateJobDefinitionRequestCronScheduleConfig = {
schedule: {
maxLength: 255,
minLength: 1,
},
timezone: {
maxLength: 255,
minLength: 1,
},
}

export const CronSchedule = {
schedule: {
maxLength: 255,
minLength: 1,
},
timezone: {
maxLength: 255,
minLength: 1,
},
}

export const ListJobDefinitionsRequest = {
page: {
greaterThanOrEqual: 1,
Expand Down Expand Up @@ -52,3 +74,14 @@ export const UpdateJobDefinitionRequest = {
pattern: /^[A-Za-z0-9-_]{3,50}$/,
},
}

export const UpdateJobDefinitionRequestCronScheduleConfig = {
schedule: {
maxLength: 255,
minLength: 1,
},
timezone: {
maxLength: 255,
minLength: 1,
},
}