diff --git a/packages/clients/src/api/jobs/v1alpha1/api.gen.ts b/packages/clients/src/api/jobs/v1alpha1/api.gen.ts index 788f4116c..90873ffcb 100644 --- a/packages/clients/src/api/jobs/v1alpha1/api.gen.ts +++ b/packages/clients/src/api/jobs/v1alpha1/api.gen.ts @@ -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) => this.client.fetch( { @@ -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) => this.client.fetch( { @@ -94,6 +106,12 @@ 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 = {}) => enrichForPagination( 'jobDefinitions', @@ -101,6 +119,13 @@ export class API extends ParentAPI { 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) => this.client.fetch( { @@ -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) => this.client.fetch({ method: 'DELETE', @@ -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) => this.client.fetch( { @@ -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) => this.client.fetch( { @@ -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) => this.client.fetch( { @@ -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 = {}) => enrichForPagination('jobRuns', this.pageOfListJobRuns, request) } diff --git a/packages/clients/src/api/jobs/v1alpha1/index.gen.ts b/packages/clients/src/api/jobs/v1alpha1/index.gen.ts index 7de779875..caf91990c 100644 --- a/packages/clients/src/api/jobs/v1alpha1/index.gen.ts +++ b/packages/clients/src/api/jobs/v1alpha1/index.gen.ts @@ -4,6 +4,8 @@ export { API } from './api.gen' export * from './content.gen' export type { CreateJobDefinitionRequest, + CreateJobDefinitionRequestCronScheduleConfig, + CronSchedule, DeleteJobDefinitionRequest, GetJobDefinitionRequest, GetJobRunRequest, @@ -19,5 +21,6 @@ export type { StartJobDefinitionRequest, StopJobRunRequest, UpdateJobDefinitionRequest, + UpdateJobDefinitionRequestCronScheduleConfig, } from './types.gen' export * as ValidationRules from './validation-rules.gen' diff --git a/packages/clients/src/api/jobs/v1alpha1/marshalling.gen.ts b/packages/clients/src/api/jobs/v1alpha1/marshalling.gen.ts index 1fd936331..0e09334d2 100644 --- a/packages/clients/src/api/jobs/v1alpha1/marshalling.gen.ts +++ b/packages/clients/src/api/jobs/v1alpha1/marshalling.gen.ts @@ -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( @@ -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, @@ -96,12 +115,27 @@ export const unmarshalListJobRunsResponse = ( } as ListJobRunsResponse } +const marshalCreateJobDefinitionRequestCronScheduleConfig = ( + request: CreateJobDefinitionRequestCronScheduleConfig, + defaults: DefaultValues, +): Record => ({ + schedule: request.schedule, + timezone: request.timezone, +}) + export const marshalCreateJobDefinitionRequest = ( request: CreateJobDefinitionRequest, defaults: DefaultValues, ): Record => ({ 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 @@ -114,12 +148,27 @@ export const marshalCreateJobDefinitionRequest = ( project_id: request.projectId ?? defaults.defaultProjectId, }) +const marshalUpdateJobDefinitionRequestCronScheduleConfig = ( + request: UpdateJobDefinitionRequestCronScheduleConfig, + defaults: DefaultValues, +): Record => ({ + schedule: request.schedule, + timezone: request.timezone, +}) + export const marshalUpdateJobDefinitionRequest = ( request: UpdateJobDefinitionRequest, defaults: DefaultValues, ): Record => ({ 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, diff --git a/packages/clients/src/api/jobs/v1alpha1/types.gen.ts b/packages/clients/src/api/jobs/v1alpha1/types.gen.ts index 8091d349a..5e3c427d8 100644 --- a/packages/clients/src/api/jobs/v1alpha1/types.gen.ts +++ b/packages/clients/src/api/jobs/v1alpha1/types.gen.ts @@ -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 @@ -30,6 +40,7 @@ export interface JobDefinition { environmentVariables: Record description: string jobTimeout?: string + cronSchedule?: CronSchedule /** * Region to target. If none is passed will use default region from the * config. @@ -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 + /** Description of the job. */ description: string + /** Timeout of the job in seconds. */ jobTimeout?: string + cronSchedule?: CreateJobDefinitionRequestCronScheduleConfig } export type DeleteJobDefinitionRequest = { @@ -79,6 +105,7 @@ export type DeleteJobDefinitionRequest = { * config. */ region?: Region + /** UUID of the job definition to delete. */ jobDefinitionId: string } @@ -88,6 +115,7 @@ export type GetJobDefinitionRequest = { * config. */ region?: Region + /** UUID of the job definition to get. */ jobDefinitionId: string } @@ -97,6 +125,7 @@ export type GetJobRunRequest = { * config. */ region?: Region + /** UUID of the job run to get. */ jobRunId: string } @@ -141,6 +170,7 @@ export type StartJobDefinitionRequest = { * config. */ region?: Region + /** UUID of the job definition to start. */ jobDefinitionId: string } @@ -150,6 +180,7 @@ export type StopJobRunRequest = { * config. */ region?: Region + /** UUID of the job run to stop. */ jobRunId: string } @@ -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 + /** Description of the job. */ description?: string + /** Timeout of the job in seconds. */ jobTimeout?: string + cronSchedule?: UpdateJobDefinitionRequestCronScheduleConfig } diff --git a/packages/clients/src/api/jobs/v1alpha1/validation-rules.gen.ts b/packages/clients/src/api/jobs/v1alpha1/validation-rules.gen.ts index 077287e93..9faef358d 100644 --- a/packages/clients/src/api/jobs/v1alpha1/validation-rules.gen.ts +++ b/packages/clients/src/api/jobs/v1alpha1/validation-rules.gen.ts @@ -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, @@ -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, + }, +}