@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.
Files changed (56) hide show
  1. package/CHANGELOG.md +12 -0
  2. package/lib/domains/job/constants/QueueBacklog.constants.d.ts +11 -0
  3. package/lib/domains/job/constants/RetryConfig.constants.d.ts +6 -1
  4. package/lib/domains/job/constants/RuntimeImage.constants.d.ts +5 -0
  5. package/lib/domains/job/errors/RuntimeImageTaskDefinitionError.d.ts +7 -0
  6. package/lib/domains/job/errors/index.d.ts +1 -0
  7. package/lib/domains/job/index.d.ts +1 -0
  8. package/lib/domains/job/manifest/JobManifestTypes.d.ts +13 -1
  9. package/lib/domains/job/model/Job/Job.d.ts +12 -0
  10. package/lib/domains/job/repository/JobExecutionRepository/JobExecutionRepository.d.ts +15 -0
  11. package/lib/domains/job/repository/JobManifestRepository/JobManifestRepository.d.ts +1 -1
  12. package/lib/domains/job/repository/JobRepository/JobRepository.d.ts +2 -2
  13. package/lib/domains/job/services/JobExecutionTaskService/JobExecutionTaskService.d.ts +1 -0
  14. package/lib/domains/job/services/JobExecutionTaskService/JobExecutionTaskService.defs.d.ts +1 -0
  15. package/lib/domains/job/utils/ResolveRuntimeImageTaskDefinitionArn/ResolveRuntimeImageTaskDefinitionArn.d.ts +6 -0
  16. package/lib/domains/job/utils/ResolveRuntimeImageTaskDefinitionArn/ResolveRuntimeImageTaskDefinitionArn.types.d.ts +9 -0
  17. package/lib/domains/job/utils/index.d.ts +2 -0
  18. package/lib/domains/manifest/index.d.ts +3 -2
  19. package/lib/domains/manifest/utils/defaultAutoRetry.d.ts +5 -0
  20. package/lib/domains/manifest/utils/defaultAutoRetry.spec.d.ts +5 -0
  21. package/lib/index.js +9 -9
  22. package/lib/index.js.map +4 -4
  23. package/package.json +2 -2
  24. package/src/domains/job/constants/QueueBacklog.constants.ts +12 -0
  25. package/src/domains/job/constants/RetryConfig.constants.ts +8 -2
  26. package/src/domains/job/constants/RuntimeImage.constants.ts +8 -2
  27. package/src/domains/job/errors/RuntimeImageTaskDefinitionError.ts +10 -0
  28. package/src/domains/job/errors/index.ts +1 -0
  29. package/src/domains/job/index.ts +1 -0
  30. package/src/domains/job/manifest/JobManifestTypes.ts +16 -1
  31. package/src/domains/job/manifest/mocks/JobManifest.mock.ts +1 -0
  32. package/src/domains/job/manifest/mocks/JobManifestDto.mock.ts +3 -0
  33. package/src/domains/job/manifest/mocks/JobManifestRecord.mock.ts +1 -0
  34. package/src/domains/job/manifest/mocks/JobManifestRequest.mock.ts +1 -0
  35. package/src/domains/job/model/Job/Job.ts +14 -0
  36. package/src/domains/job/model/Job/mocks/Job.mock.ts +2 -0
  37. package/src/domains/job/model/Job/mocks/JobDto.mock.ts +4 -0
  38. package/src/domains/job/model/Job/mocks/JobRecord.mock.ts +2 -0
  39. package/src/domains/job/model/Job/mocks/JobRequest.mock.ts +2 -0
  40. package/src/domains/job/repository/JobExecutionRepository/JobExecutionRepository.spec.ts +65 -0
  41. package/src/domains/job/repository/JobExecutionRepository/JobExecutionRepository.ts +53 -0
  42. package/src/domains/job/repository/JobManifestRepository/JobManifestRepository.spec.ts +56 -4
  43. package/src/domains/job/repository/JobManifestRepository/JobManifestRepository.ts +14 -4
  44. package/src/domains/job/repository/JobRepository/JobRepository.spec.ts +36 -4
  45. package/src/domains/job/repository/JobRepository/JobRepository.ts +10 -5
  46. package/src/domains/job/services/JobExecutionTaskService/JobExecutionTaskService.defs.ts +1 -0
  47. package/src/domains/job/services/JobExecutionTaskService/JobExecutionTaskService.spec.ts +53 -3
  48. package/src/domains/job/services/JobExecutionTaskService/JobExecutionTaskService.ts +19 -8
  49. package/src/domains/job/services/JobManifestService/JobManifestService.spec.ts +9 -8
  50. package/src/domains/job/utils/ResolveRuntimeImageTaskDefinitionArn/ResolveRuntimeImageTaskDefinitionArn.ts +39 -0
  51. package/src/domains/job/utils/ResolveRuntimeImageTaskDefinitionArn/ResolveRuntimeImageTaskDefinitionArn.types.ts +10 -0
  52. package/src/domains/job/utils/index.ts +2 -0
  53. package/src/domains/manifest/index.ts +3 -2
  54. package/src/domains/manifest/utils/defaultAutoRetry.spec.ts +16 -0
  55. package/src/domains/manifest/utils/defaultAutoRetry.ts +6 -0
  56. package/src/domains/manifest/utils/validateRuntimeImage.spec.ts +11 -12
package/CHANGELOG.md CHANGED
@@ -1,5 +1,17 @@
1
1
  # Change Log
2
2
 
3
+ ## 2.9.0
4
+
5
+ ### Minor Changes
6
+
7
+ - 89bb566: Mark node:20 runtime image as deprecated
8
+
9
+ ## 2.8.0
10
+
11
+ ### Minor Changes
12
+
13
+ - ce08dad: Added autoRetry support to job runner
14
+
3
15
  ## 2.7.0
4
16
 
5
17
  ### Minor Changes
@@ -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
+ };
@@ -0,0 +1,7 @@
1
+ /*!
2
+ * @license
3
+ * Copyright Squiz Australia Pty Ltd. All Rights Reserved.
4
+ */
5
+ export declare class RuntimeImageTaskDefinitionError extends Error {
6
+ constructor(message: string);
7
+ }
@@ -6,3 +6,4 @@ export * from './NotFoundError';
6
6
  export * from './NotImplementedError';
7
7
  export * from './UnprocessableContent';
8
8
  export * from './ExecutionStatusError';
9
+ export * from './RuntimeImageTaskDefinitionError';
@@ -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>;
@@ -22,4 +22,5 @@ export declare class JobExecutionTaskService {
22
22
  runJobExecutionTask(params: RunJobTaskParams): Promise<string | undefined>;
23
23
  private computeJobExecutionClientToken;
24
24
  private createJobDetailsFile;
25
+ private findJobManifest;
25
26
  }
@@ -15,5 +15,6 @@ export interface RunJobTaskParams {
15
15
  shortEnvironment: string;
16
16
  clusterArn: string;
17
17
  taskDefinitionArn: string;
18
+ taskDefinitionArnsByRuntimeImage: Record<string, string>;
18
19
  tenantId: string;
19
20
  }
@@ -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';
@@ -0,0 +1,5 @@
1
+ /*!
2
+ * @license
3
+ * Copyright Squiz Australia Pty Ltd. All Rights Reserved.
4
+ */
5
+ export declare const defaultAutoRetry: (autoRetry: boolean | null | undefined) => boolean;
@@ -0,0 +1,5 @@
1
+ /*!
2
+ * @license
3
+ * Copyright Squiz Australia Pty Ltd. All Rights Reserved.
4
+ */
5
+ export {};