@squiz/job-runner-lib 2.7.0 → 2.9.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +12 -0
- package/lib/domains/job/constants/QueueBacklog.constants.d.ts +11 -0
- package/lib/domains/job/constants/RetryConfig.constants.d.ts +6 -1
- package/lib/domains/job/constants/RuntimeImage.constants.d.ts +5 -0
- package/lib/domains/job/errors/RuntimeImageTaskDefinitionError.d.ts +7 -0
- package/lib/domains/job/errors/index.d.ts +1 -0
- package/lib/domains/job/index.d.ts +1 -0
- package/lib/domains/job/manifest/JobManifestTypes.d.ts +13 -1
- package/lib/domains/job/model/Job/Job.d.ts +12 -0
- package/lib/domains/job/repository/JobExecutionRepository/JobExecutionRepository.d.ts +15 -0
- package/lib/domains/job/repository/JobManifestRepository/JobManifestRepository.d.ts +1 -1
- package/lib/domains/job/repository/JobRepository/JobRepository.d.ts +2 -2
- package/lib/domains/job/services/JobExecutionTaskService/JobExecutionTaskService.d.ts +1 -0
- package/lib/domains/job/services/JobExecutionTaskService/JobExecutionTaskService.defs.d.ts +1 -0
- package/lib/domains/job/utils/ResolveRuntimeImageTaskDefinitionArn/ResolveRuntimeImageTaskDefinitionArn.d.ts +6 -0
- package/lib/domains/job/utils/ResolveRuntimeImageTaskDefinitionArn/ResolveRuntimeImageTaskDefinitionArn.types.d.ts +9 -0
- package/lib/domains/job/utils/index.d.ts +2 -0
- package/lib/domains/manifest/index.d.ts +3 -2
- package/lib/domains/manifest/utils/defaultAutoRetry.d.ts +5 -0
- package/lib/domains/manifest/utils/defaultAutoRetry.spec.d.ts +5 -0
- package/lib/index.js +9 -9
- package/lib/index.js.map +4 -4
- package/package.json +2 -2
- package/src/domains/job/constants/QueueBacklog.constants.ts +12 -0
- package/src/domains/job/constants/RetryConfig.constants.ts +8 -2
- package/src/domains/job/constants/RuntimeImage.constants.ts +8 -2
- package/src/domains/job/errors/RuntimeImageTaskDefinitionError.ts +10 -0
- package/src/domains/job/errors/index.ts +1 -0
- package/src/domains/job/index.ts +1 -0
- package/src/domains/job/manifest/JobManifestTypes.ts +16 -1
- package/src/domains/job/manifest/mocks/JobManifest.mock.ts +1 -0
- package/src/domains/job/manifest/mocks/JobManifestDto.mock.ts +3 -0
- package/src/domains/job/manifest/mocks/JobManifestRecord.mock.ts +1 -0
- package/src/domains/job/manifest/mocks/JobManifestRequest.mock.ts +1 -0
- package/src/domains/job/model/Job/Job.ts +14 -0
- package/src/domains/job/model/Job/mocks/Job.mock.ts +2 -0
- package/src/domains/job/model/Job/mocks/JobDto.mock.ts +4 -0
- package/src/domains/job/model/Job/mocks/JobRecord.mock.ts +2 -0
- package/src/domains/job/model/Job/mocks/JobRequest.mock.ts +2 -0
- package/src/domains/job/repository/JobExecutionRepository/JobExecutionRepository.spec.ts +65 -0
- package/src/domains/job/repository/JobExecutionRepository/JobExecutionRepository.ts +53 -0
- package/src/domains/job/repository/JobManifestRepository/JobManifestRepository.spec.ts +56 -4
- package/src/domains/job/repository/JobManifestRepository/JobManifestRepository.ts +14 -4
- package/src/domains/job/repository/JobRepository/JobRepository.spec.ts +36 -4
- package/src/domains/job/repository/JobRepository/JobRepository.ts +10 -5
- package/src/domains/job/services/JobExecutionTaskService/JobExecutionTaskService.defs.ts +1 -0
- package/src/domains/job/services/JobExecutionTaskService/JobExecutionTaskService.spec.ts +53 -3
- package/src/domains/job/services/JobExecutionTaskService/JobExecutionTaskService.ts +19 -8
- package/src/domains/job/services/JobManifestService/JobManifestService.spec.ts +9 -8
- package/src/domains/job/utils/ResolveRuntimeImageTaskDefinitionArn/ResolveRuntimeImageTaskDefinitionArn.ts +39 -0
- package/src/domains/job/utils/ResolveRuntimeImageTaskDefinitionArn/ResolveRuntimeImageTaskDefinitionArn.types.ts +10 -0
- package/src/domains/job/utils/index.ts +2 -0
- package/src/domains/manifest/index.ts +3 -2
- package/src/domains/manifest/utils/defaultAutoRetry.spec.ts +16 -0
- package/src/domains/manifest/utils/defaultAutoRetry.ts +6 -0
- package/src/domains/manifest/utils/validateRuntimeImage.spec.ts +11 -12
package/CHANGELOG.md
CHANGED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright Squiz Australia Pty Ltd. All Rights Reserved.
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* Backlog guard defaults. A job's `begin` is rejected with 422 once it has more than
|
|
7
|
+
* DEFAULT_MAX_QUEUED_EXECUTIONS queued AND its oldest queued execution is older than
|
|
8
|
+
* DEFAULT_MAX_QUEUED_AGE_HOURS. Both conditions are required (large AND stale).
|
|
9
|
+
*/
|
|
10
|
+
export declare const DEFAULT_MAX_QUEUED_EXECUTIONS = 500;
|
|
11
|
+
export declare const DEFAULT_MAX_QUEUED_AGE_HOURS = 2;
|
|
@@ -6,13 +6,18 @@
|
|
|
6
6
|
* Retry configuration with exponential backoff delays in seconds.
|
|
7
7
|
* Using SQS message timer limits (max 15 minutes = 900 seconds).
|
|
8
8
|
*
|
|
9
|
-
* Delays: 30s, 1min, 2min, 5min, 10min, 15min
|
|
9
|
+
* Delays: 30s, 1min, 2min, 5min, 10min, then 15min thereafter.
|
|
10
10
|
*/
|
|
11
11
|
export declare const RETRY_DELAYS_SECONDS: ReadonlyArray<number>;
|
|
12
12
|
/**
|
|
13
13
|
* Maximum number of retry attempts for container start failures.
|
|
14
14
|
*/
|
|
15
15
|
export declare const MAX_RETRY_ATTEMPTS: number;
|
|
16
|
+
/**
|
|
17
|
+
* Maximum number of total attempts for opted-in job code failures.
|
|
18
|
+
* This allows the initial attempt plus 3 retries.
|
|
19
|
+
*/
|
|
20
|
+
export declare const MAX_JOB_CODE_RETRY_ATTEMPTS = 4;
|
|
16
21
|
/**
|
|
17
22
|
* After a job has attempted to be started this number of times alerts will start to be sent.
|
|
18
23
|
*/
|
|
@@ -9,3 +9,8 @@ export declare const DEPRECATED_RUNTIME_IMAGES: readonly string[];
|
|
|
9
9
|
export declare const getRuntimeImageOrDefault: (image: string | null | undefined) => string;
|
|
10
10
|
export declare const isSupportedRuntimeImage: (image: string) => boolean;
|
|
11
11
|
export declare const isDeprecatedRuntimeImage: (image: string) => boolean;
|
|
12
|
+
export declare const getRuntimeImagesMetadata: () => {
|
|
13
|
+
supportedRuntimeImages: ("node:20" | "node:24")[];
|
|
14
|
+
deprecatedRuntimeImages: string[];
|
|
15
|
+
recommendedRuntimeImage: string;
|
|
16
|
+
};
|
|
@@ -2,6 +2,7 @@ export * from './core/dynamoClient.mock';
|
|
|
2
2
|
export * from './core/pagination';
|
|
3
3
|
export * from './constants/InjectTokens';
|
|
4
4
|
export * from './constants/JobExecutionStatus.constants';
|
|
5
|
+
export * from './constants/QueueBacklog.constants';
|
|
5
6
|
export * from './constants/Repository.constants';
|
|
6
7
|
export * from './constants/RetryConfig.constants';
|
|
7
8
|
export * from './constants/RuntimeImage.constants';
|
|
@@ -55,6 +55,12 @@ export interface JobManifest {
|
|
|
55
55
|
* @memberof JobManifest
|
|
56
56
|
*/
|
|
57
57
|
image: string;
|
|
58
|
+
/**
|
|
59
|
+
* Whether failed job code executions should be retried automatically.
|
|
60
|
+
* @type {boolean}
|
|
61
|
+
* @memberof JobManifest
|
|
62
|
+
*/
|
|
63
|
+
autoRetry: boolean;
|
|
58
64
|
/**
|
|
59
65
|
* The DynamoDB record type ('job').
|
|
60
66
|
* @type {EntityType}
|
|
@@ -124,13 +130,19 @@ export interface JobManifestRecord {
|
|
|
124
130
|
* @memberof JobManifestRecord
|
|
125
131
|
*/
|
|
126
132
|
image: string;
|
|
133
|
+
/**
|
|
134
|
+
* Whether failed job code executions should be retried automatically.
|
|
135
|
+
* @type {boolean}
|
|
136
|
+
* @memberof JobManifestRecord
|
|
137
|
+
*/
|
|
138
|
+
autoRetry: boolean;
|
|
127
139
|
}
|
|
128
140
|
export type JobManifestDto = Record<keyof JobManifestRecord, AttributeValue>;
|
|
129
141
|
/**
|
|
130
142
|
* The request body for creating a job (POST /job-manifest).
|
|
131
143
|
* @export
|
|
132
144
|
*/
|
|
133
|
-
export type CreateJobManifestRequest = Omit<JobManifest, 'type'
|
|
145
|
+
export type CreateJobManifestRequest = Omit<JobManifest, 'type' | 'autoRetry'> & Partial<Pick<JobManifest, 'autoRetry'>>;
|
|
134
146
|
/**
|
|
135
147
|
* The request body for updating a job (PUT /job-manifest).
|
|
136
148
|
* @export
|
|
@@ -29,6 +29,12 @@ export interface Job {
|
|
|
29
29
|
* @memberof Job
|
|
30
30
|
*/
|
|
31
31
|
version: string;
|
|
32
|
+
/**
|
|
33
|
+
* The runtime image the job should execute against (e.g. `node:20`, `node:24`).
|
|
34
|
+
* @type {string}
|
|
35
|
+
* @memberof Job
|
|
36
|
+
*/
|
|
37
|
+
image: string;
|
|
32
38
|
/**
|
|
33
39
|
* The DynamoDB record type ('job').
|
|
34
40
|
* @type {EntityType}
|
|
@@ -72,6 +78,12 @@ export interface JobRecord {
|
|
|
72
78
|
* @memberof JobRecord
|
|
73
79
|
*/
|
|
74
80
|
version: string;
|
|
81
|
+
/**
|
|
82
|
+
* The runtime image the job should execute against (e.g. `node:20`, `node:24`).
|
|
83
|
+
* @type {string}
|
|
84
|
+
* @memberof JobRecord
|
|
85
|
+
*/
|
|
86
|
+
image: string;
|
|
75
87
|
}
|
|
76
88
|
export type JobDto = Record<keyof JobRecord, AttributeValue>;
|
|
77
89
|
/**
|
|
@@ -16,6 +16,21 @@ export declare class JobExecutionRepository extends Repository<JobExecution, Job
|
|
|
16
16
|
* @memberof JobExecutionRepository
|
|
17
17
|
*/
|
|
18
18
|
list(parameters?: ListJobExecutionParameters): Promise<Array<JobExecution>>;
|
|
19
|
+
/**
|
|
20
|
+
* Returns the single oldest queued execution for a job, or null if there are none.
|
|
21
|
+
*
|
|
22
|
+
* Queries the `lsi1` index (`lsi1sk = "<status>~<jobName>"`). All queued executions of one
|
|
23
|
+
* job share the same `lsi1sk`, so DynamoDB breaks ties by the base-table `sk`
|
|
24
|
+
* (`"<jobName>~<id>"`); `id` is prefixed with the ISO `timeQueued`, which sorts
|
|
25
|
+
* lexicographically, so ascending order is chronological and the first item is the oldest.
|
|
26
|
+
*/
|
|
27
|
+
getOldestQueuedExecution(jobName: string): Promise<JobExecution | null>;
|
|
28
|
+
/**
|
|
29
|
+
* Counts queued executions for a job, evaluating at most `limit` items (`Select: COUNT` so no
|
|
30
|
+
* item data is returned). Pass a `limit` just above the threshold you care about — queued
|
|
31
|
+
* items are small, so a single page covers the bounded count.
|
|
32
|
+
*/
|
|
33
|
+
countQueuedExecutions(jobName: string, limit?: number): Promise<number>;
|
|
19
34
|
/**
|
|
20
35
|
* Get list of records from database.
|
|
21
36
|
* @abstract
|
|
@@ -3,8 +3,8 @@
|
|
|
3
3
|
* Copyright Squiz Australia Pty Ltd. All Rights Reserved.
|
|
4
4
|
*/
|
|
5
5
|
import { DynamoDBClient } from '@aws-sdk/client-dynamodb';
|
|
6
|
-
import { Repository } from '../AbstractRepository';
|
|
7
6
|
import { CreateJobManifestRequest, JobManifest, JobManifestDto, JobManifestSk, UpdateJobManifestRequest } from '../../manifest';
|
|
7
|
+
import { Repository } from '../AbstractRepository';
|
|
8
8
|
export declare class JobManifestRepository extends Repository<JobManifest, JobManifestDto, JobManifestSk> {
|
|
9
9
|
constructor(dynamoDbClient: DynamoDBClient, tableName: string, tenant: string);
|
|
10
10
|
create(input: CreateJobManifestRequest): Promise<JobManifest>;
|
|
@@ -3,9 +3,9 @@
|
|
|
3
3
|
* Copyright Squiz Australia Pty Ltd. All Rights Reserved.
|
|
4
4
|
*/
|
|
5
5
|
import { DynamoDBClient } from '@aws-sdk/client-dynamodb';
|
|
6
|
-
import { Repository } from '../AbstractRepository';
|
|
7
|
-
import { CreateJobRequest, Job, JobDto, JobSk, ListJobParameters } from '../../model/Job';
|
|
8
6
|
import { PaginationInfo, PaginationQueryResponse } from '../../core/pagination';
|
|
7
|
+
import { CreateJobRequest, Job, JobDto, JobSk, ListJobParameters } from '../../model/Job';
|
|
8
|
+
import { Repository } from '../AbstractRepository';
|
|
9
9
|
export declare class JobRepository extends Repository<Job, JobDto, JobSk> {
|
|
10
10
|
constructor(dynamoDbClient: DynamoDBClient, tableName: string, tenant: string);
|
|
11
11
|
create(input: CreateJobRequest): Promise<Job>;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright Squiz Australia Pty Ltd. All Rights Reserved.
|
|
4
|
+
*/
|
|
5
|
+
import { ResolveRuntimeImageTaskDefinitionArnParams } from './ResolveRuntimeImageTaskDefinitionArn.types';
|
|
6
|
+
export declare const resolveRuntimeImageTaskDefinitionArn: ({ image, taskDefinitionArnsByRuntimeImage, legacyTaskDefinitionArn, }: ResolveRuntimeImageTaskDefinitionArnParams) => string;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright Squiz Australia Pty Ltd. All Rights Reserved.
|
|
4
|
+
*/
|
|
5
|
+
export interface ResolveRuntimeImageTaskDefinitionArnParams {
|
|
6
|
+
image: string | null | undefined;
|
|
7
|
+
taskDefinitionArnsByRuntimeImage: Record<string, string>;
|
|
8
|
+
legacyTaskDefinitionArn: string;
|
|
9
|
+
}
|
|
@@ -3,3 +3,5 @@ export * from './GetAwsTags/GetAwsTags.types';
|
|
|
3
3
|
export * from './SlackClient/SlackClient';
|
|
4
4
|
export * from './SlackClient/types/SlackClient.types';
|
|
5
5
|
export * from './SortByTimeQueued/SortByTimeQueued';
|
|
6
|
+
export * from './ResolveRuntimeImageTaskDefinitionArn/ResolveRuntimeImageTaskDefinitionArn';
|
|
7
|
+
export * from './ResolveRuntimeImageTaskDefinitionArn/ResolveRuntimeImageTaskDefinitionArn.types';
|
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
export * from './services/ManifestServiceForDev';
|
|
2
1
|
export * from './services/JobFunctionService';
|
|
2
|
+
export * from './services/ManifestServiceForDev';
|
|
3
|
+
export * from './utils/defaultAutoRetry';
|
|
3
4
|
export * from './utils/getAndAssertJobManifestVersion';
|
|
4
5
|
export * from './utils/isValidManifestVersion';
|
|
5
6
|
export * from './utils/validateRuntimeImage';
|
|
6
|
-
export * from './ManifestModel';
|
|
7
7
|
export * from '../job/manifest/JobManifestV1';
|
|
8
8
|
export * from './errors/ManifestValidationError';
|
|
9
|
+
export * from './ManifestModel';
|