@punks/backend-entity-manager 0.0.470 → 0.0.472
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/dist/cjs/index.js +76 -16
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/types/abstractions/pipelines.d.ts +1 -0
- package/dist/cjs/types/platforms/nest/decorators/pipelines.d.ts +9 -0
- package/dist/cjs/types/platforms/nest/pipelines/template/template.d.ts +6 -1
- package/dist/cjs/types/platforms/nest/plugins/jobs/aws-batch/manager/index.d.ts +1 -0
- package/dist/cjs/types/platforms/nest/plugins/jobs/aws-batch/manager/types.d.ts +4 -0
- package/dist/cjs/types/platforms/nest/plugins/jobs/aws-batch/models/index.d.ts +1 -0
- package/dist/cjs/types/platforms/nest/plugins/jobs/aws-batch/settings/index.d.ts +2 -1
- package/dist/esm/index.js +77 -17
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/types/abstractions/pipelines.d.ts +1 -0
- package/dist/esm/types/platforms/nest/decorators/pipelines.d.ts +9 -0
- package/dist/esm/types/platforms/nest/pipelines/template/template.d.ts +6 -1
- package/dist/esm/types/platforms/nest/plugins/jobs/aws-batch/manager/index.d.ts +1 -0
- package/dist/esm/types/platforms/nest/plugins/jobs/aws-batch/manager/types.d.ts +4 -0
- package/dist/esm/types/platforms/nest/plugins/jobs/aws-batch/models/index.d.ts +1 -0
- package/dist/esm/types/platforms/nest/plugins/jobs/aws-batch/settings/index.d.ts +2 -1
- package/dist/index.d.ts +17 -2
- package/package.json +3 -3
|
@@ -8,3 +8,4 @@ export interface IPipelinesController {
|
|
|
8
8
|
export interface IPipelineOperationExecutor<TPipelineInput, TPipelineOutput, TContext> {
|
|
9
9
|
execute(input: TPipelineInput, context: TContext): Promise<PipelineOperationResult<TPipelineInput, TPipelineOutput>>;
|
|
10
10
|
}
|
|
11
|
+
export type PipelineConcurrency = "exclusive" | "sequential";
|
|
@@ -1,4 +1,13 @@
|
|
|
1
|
+
import { PipelineConcurrency } from "../../../abstractions/pipelines";
|
|
2
|
+
export type PipelineTemplateOptions = {
|
|
3
|
+
logging?: {
|
|
4
|
+
enabled?: boolean;
|
|
5
|
+
ignoreMeta?: boolean;
|
|
6
|
+
};
|
|
7
|
+
};
|
|
1
8
|
export type PipelineTemplateProps = {
|
|
2
9
|
name: string;
|
|
10
|
+
concurrency?: PipelineConcurrency;
|
|
11
|
+
options?: PipelineTemplateOptions;
|
|
3
12
|
};
|
|
4
13
|
export declare const WpPipeline: (name: string, props?: Omit<PipelineTemplateProps, "name">) => <TFunction extends Function, Y>(target: object | TFunction, propertyKey?: string | symbol | undefined, descriptor?: TypedPropertyDescriptor<Y> | undefined) => void;
|
|
@@ -2,9 +2,12 @@ import { PipelineDefinition, PipelineResult } from "../../../../types";
|
|
|
2
2
|
import { IPipelineTemplateBuilder } from "../builder/types";
|
|
3
3
|
import { PipelineUtils } from "./utils";
|
|
4
4
|
import { PipelineTemplateProps } from "../../decorators";
|
|
5
|
-
|
|
5
|
+
import { PipelineConcurrency } from "../../../../abstractions/pipelines";
|
|
6
6
|
export type PipelineTemplateOptions = {
|
|
7
7
|
concurrency?: PipelineConcurrency;
|
|
8
|
+
logging?: {
|
|
9
|
+
ignoreMeta?: boolean;
|
|
10
|
+
};
|
|
8
11
|
};
|
|
9
12
|
export declare abstract class NestPipelineTemplate<TPipelineInput, TPipelineOutput, TContext> {
|
|
10
13
|
private readonly options?;
|
|
@@ -21,9 +24,11 @@ export declare abstract class NestPipelineTemplate<TPipelineInput, TPipelineOutp
|
|
|
21
24
|
context: TContext;
|
|
22
25
|
}): Promise<PipelineResult<TPipelineInput, TPipelineOutput>>;
|
|
23
26
|
private pipelineExecute;
|
|
27
|
+
private processLogMetadata;
|
|
24
28
|
private getDefinition;
|
|
25
29
|
private buildDefinition;
|
|
26
30
|
private getContext;
|
|
31
|
+
private get concurrency();
|
|
27
32
|
private get operationsLockService();
|
|
28
33
|
private get controller();
|
|
29
34
|
private get registry();
|
|
@@ -9,6 +9,7 @@ export type BathJobDefinition = {
|
|
|
9
9
|
};
|
|
10
10
|
export type BatchJobOverrides = {
|
|
11
11
|
command?: string[];
|
|
12
|
+
batchComputeEnvironment?: string;
|
|
12
13
|
};
|
|
13
14
|
export type SubmitBatchJobInput = {
|
|
14
15
|
overrides?: BatchJobOverrides;
|
|
@@ -24,3 +25,6 @@ export type AwsJobDefinition = {
|
|
|
24
25
|
infrastructureParams: AwsBatchInfrastructureParams;
|
|
25
26
|
invocationParams: AwsBatchInvocationParams;
|
|
26
27
|
};
|
|
28
|
+
export type AwsBatchCreateQueueOptions = {
|
|
29
|
+
batchComputeEnvironment: string;
|
|
30
|
+
};
|
|
@@ -3,7 +3,8 @@ export type AwsBatchSettings = {
|
|
|
3
3
|
awsAccessKeyId?: string;
|
|
4
4
|
awsSecretAccessKey?: string;
|
|
5
5
|
region?: string;
|
|
6
|
-
|
|
6
|
+
defaultFargateBatchComputeEnvironment: string;
|
|
7
|
+
defaultEc2BatchComputeEnvironment?: string;
|
|
7
8
|
batchExecutionRole: string;
|
|
8
9
|
batchResourcesPrefix: string;
|
|
9
10
|
};
|
package/dist/esm/index.js
CHANGED
|
@@ -20,7 +20,7 @@ import { ListObjectsCommand, PutObjectCommand, GetObjectCommand, DeleteObjectCom
|
|
|
20
20
|
import { getSignedUrl } from '@aws-sdk/s3-request-presigner';
|
|
21
21
|
import { SendEmailCommand, SESClient } from '@aws-sdk/client-ses';
|
|
22
22
|
import { MailService } from '@sendgrid/mail';
|
|
23
|
-
import { BatchClient, CancelJobCommand, ListJobsCommand, SubmitJobCommand, DeregisterJobDefinitionCommand, RegisterJobDefinitionCommand, JobDefinitionType,
|
|
23
|
+
import { BatchClient, CancelJobCommand, ListJobsCommand, PlatformCapability, SubmitJobCommand, DeregisterJobDefinitionCommand, RegisterJobDefinitionCommand, JobDefinitionType, ResourceType, AssignPublicIp, DescribeJobDefinitionsCommand, CreateJobQueueCommand, UpdateJobQueueCommand, DescribeJobQueuesCommand, JobStatus as JobStatus$1 } from '@aws-sdk/client-batch';
|
|
24
24
|
import { CloudWatchLogsClient, DescribeLogGroupsCommand, CreateLogGroupCommand } from '@aws-sdk/client-cloudwatch-logs';
|
|
25
25
|
import require$$1$1 from 'http';
|
|
26
26
|
import require$$2 from 'https';
|
|
@@ -35581,7 +35581,7 @@ class NestPipelineTemplate {
|
|
|
35581
35581
|
return result.output;
|
|
35582
35582
|
}
|
|
35583
35583
|
async execute(data) {
|
|
35584
|
-
if (this.
|
|
35584
|
+
if (this.concurrency === "sequential") {
|
|
35585
35585
|
return await this.operationsLockService.executeSequential({
|
|
35586
35586
|
lockUid: this.getConcurrencyKey(data.input),
|
|
35587
35587
|
operation: async () => {
|
|
@@ -35589,7 +35589,7 @@ class NestPipelineTemplate {
|
|
|
35589
35589
|
},
|
|
35590
35590
|
});
|
|
35591
35591
|
}
|
|
35592
|
-
if (this.
|
|
35592
|
+
if (this.concurrency === "exclusive") {
|
|
35593
35593
|
const result = await this.operationsLockService.executeExclusive({
|
|
35594
35594
|
lockUid: this.getConcurrencyKey(data.input),
|
|
35595
35595
|
operation: async () => {
|
|
@@ -35607,9 +35607,9 @@ class NestPipelineTemplate {
|
|
|
35607
35607
|
context: data.context,
|
|
35608
35608
|
instanceId,
|
|
35609
35609
|
};
|
|
35610
|
-
this.logger.debug(`[START] | ${this.metadata.name}`, logMetadata);
|
|
35610
|
+
this.logger.debug(`[START] | ${this.metadata.name}`, this.processLogMetadata(logMetadata));
|
|
35611
35611
|
if (!this.isAuthorized(data.context)) {
|
|
35612
|
-
this.logger.debug(`[ERROR] | ${this.metadata.name} -> Unauthorized`, logMetadata);
|
|
35612
|
+
this.logger.debug(`[ERROR] | ${this.metadata.name} -> Unauthorized`, this.processLogMetadata(logMetadata));
|
|
35613
35613
|
return {
|
|
35614
35614
|
type: "error",
|
|
35615
35615
|
errorType: PipelineErrorType.Unauthorized,
|
|
@@ -35622,19 +35622,25 @@ class NestPipelineTemplate {
|
|
|
35622
35622
|
if (result.type === "error") {
|
|
35623
35623
|
this.logger.error(`[ERROR] | ${this.metadata.name} -> ${result.exception
|
|
35624
35624
|
? `exception: ${result.exception.name}\n${result.exception.stack}`
|
|
35625
|
-
: ""}`, {
|
|
35625
|
+
: ""}`, this.processLogMetadata({
|
|
35626
35626
|
...logMetadata,
|
|
35627
35627
|
result,
|
|
35628
|
-
});
|
|
35628
|
+
}));
|
|
35629
35629
|
}
|
|
35630
35630
|
else {
|
|
35631
|
-
this.logger.debug(`[COMPLETED] | ${this.metadata.name}`, {
|
|
35631
|
+
this.logger.debug(`[COMPLETED] | ${this.metadata.name}`, this.processLogMetadata({
|
|
35632
35632
|
...logMetadata,
|
|
35633
35633
|
result,
|
|
35634
|
-
});
|
|
35634
|
+
}));
|
|
35635
35635
|
}
|
|
35636
35636
|
return result;
|
|
35637
35637
|
}
|
|
35638
|
+
processLogMetadata(meta) {
|
|
35639
|
+
if (this.metadata.options?.logging?.ignoreMeta) {
|
|
35640
|
+
return undefined;
|
|
35641
|
+
}
|
|
35642
|
+
return meta;
|
|
35643
|
+
}
|
|
35638
35644
|
getDefinition() {
|
|
35639
35645
|
if (!this.cachedDefinition) {
|
|
35640
35646
|
this.cachedDefinition = this.buildDefinition();
|
|
@@ -35651,6 +35657,9 @@ class NestPipelineTemplate {
|
|
|
35651
35657
|
.resolveAuthenticationContextProvider();
|
|
35652
35658
|
return (await contextService?.getContext());
|
|
35653
35659
|
}
|
|
35660
|
+
get concurrency() {
|
|
35661
|
+
return this.options?.concurrency ?? this.metadata.concurrency;
|
|
35662
|
+
}
|
|
35654
35663
|
get operationsLockService() {
|
|
35655
35664
|
return this.registry
|
|
35656
35665
|
.getContainer()
|
|
@@ -41539,9 +41548,25 @@ let AwsBatchService = AwsBatchService_1 = class AwsBatchService {
|
|
|
41539
41548
|
this.logger.info(`AWS JOB -> submitting job triggered`, {
|
|
41540
41549
|
input,
|
|
41541
41550
|
});
|
|
41542
|
-
const queue = await this.ensureQueue(jobQueueName(input.jobUid));
|
|
41543
41551
|
const jobDefName = jobDefinitionName(input.jobUid);
|
|
41544
41552
|
const jobDefinition = await this.getLatestJobDefinition(jobDefName);
|
|
41553
|
+
if (!jobDefinition) {
|
|
41554
|
+
throw new Error(`Job definition not found -> ${jobDefName}`);
|
|
41555
|
+
}
|
|
41556
|
+
const platformType = jobDefinition.platformCapabilities?.[0];
|
|
41557
|
+
if (!platformType) {
|
|
41558
|
+
throw new Error(`Platform type not found -> ${jobDefName}`);
|
|
41559
|
+
}
|
|
41560
|
+
const defaultComputeEnvironment = platformType === PlatformCapability.FARGATE
|
|
41561
|
+
? this.awsSettings.defaultFargateBatchComputeEnvironment
|
|
41562
|
+
: this.awsSettings.defaultEc2BatchComputeEnvironment;
|
|
41563
|
+
const batchComputeEnvironment = input.overrides?.batchComputeEnvironment ?? defaultComputeEnvironment;
|
|
41564
|
+
if (!batchComputeEnvironment) {
|
|
41565
|
+
throw new Error(`Compute environment not found -> ${jobDefName}`);
|
|
41566
|
+
}
|
|
41567
|
+
const queue = await this.ensureQueue(jobQueueName(input.jobUid), {
|
|
41568
|
+
batchComputeEnvironment,
|
|
41569
|
+
});
|
|
41545
41570
|
const jobName = jobInstanceName(input.jobUid, input.instanceId);
|
|
41546
41571
|
const submitJobRequest = {
|
|
41547
41572
|
jobQueue: queue.jobQueueArn,
|
|
@@ -41668,18 +41693,32 @@ let AwsBatchService = AwsBatchService_1 = class AwsBatchService {
|
|
|
41668
41693
|
}));
|
|
41669
41694
|
return result.jobDefinitions ?? [];
|
|
41670
41695
|
}
|
|
41671
|
-
async ensureQueue(queueName) {
|
|
41696
|
+
async ensureQueue(queueName, options) {
|
|
41672
41697
|
if (!queueName) {
|
|
41673
41698
|
throw new Error(`Queue name not provided`);
|
|
41674
41699
|
}
|
|
41675
41700
|
this.logger.debug(`AWS JOB -> ensuring queue ${queueName}`);
|
|
41676
41701
|
const queue = await this.getQueue(queueName);
|
|
41677
41702
|
if (queue) {
|
|
41678
|
-
|
|
41679
|
-
|
|
41703
|
+
if (queue.computeEnvironmentOrder?.[0].computeEnvironment ===
|
|
41704
|
+
options.batchComputeEnvironment) {
|
|
41705
|
+
this.logger.debug(`AWS JOB -> queue exists ${queueName}`);
|
|
41706
|
+
return queue;
|
|
41707
|
+
}
|
|
41708
|
+
this.logger.debug(`AWS JOB -> queue exists with different compute environment ${queueName}`, {
|
|
41709
|
+
queue,
|
|
41710
|
+
options,
|
|
41711
|
+
});
|
|
41712
|
+
await this.updateQueue(queueName, options);
|
|
41713
|
+
this.logger.debug(`AWS JOB -> queue updated ${queueName}`);
|
|
41714
|
+
const updatedQueue = await this.getQueue(queueName);
|
|
41715
|
+
if (!updatedQueue) {
|
|
41716
|
+
throw new Error(`Queue not updated -> ${queueName}`);
|
|
41717
|
+
}
|
|
41718
|
+
return updatedQueue;
|
|
41680
41719
|
}
|
|
41681
41720
|
this.logger.debug(`AWS JOB -> creating queue ${queueName}`);
|
|
41682
|
-
await this.createQueue(queueName);
|
|
41721
|
+
await this.createQueue(queueName, options);
|
|
41683
41722
|
this.logger.debug(`AWS JOB -> queue created ${queueName}`);
|
|
41684
41723
|
// Wait for the queue to be active
|
|
41685
41724
|
await sleep(10000);
|
|
@@ -41689,8 +41728,9 @@ let AwsBatchService = AwsBatchService_1 = class AwsBatchService {
|
|
|
41689
41728
|
}
|
|
41690
41729
|
return currentQueue;
|
|
41691
41730
|
}
|
|
41692
|
-
async createQueue(queueName) {
|
|
41693
|
-
if (!this.awsSettings.
|
|
41731
|
+
async createQueue(queueName, options) {
|
|
41732
|
+
if (!this.awsSettings.defaultFargateBatchComputeEnvironment &&
|
|
41733
|
+
!options?.batchComputeEnvironment) {
|
|
41694
41734
|
throw new Error(`No compute environment defined`);
|
|
41695
41735
|
}
|
|
41696
41736
|
await this.client().send(new CreateJobQueueCommand({
|
|
@@ -41698,7 +41738,25 @@ let AwsBatchService = AwsBatchService_1 = class AwsBatchService {
|
|
|
41698
41738
|
priority: 0,
|
|
41699
41739
|
computeEnvironmentOrder: [
|
|
41700
41740
|
{
|
|
41701
|
-
computeEnvironment:
|
|
41741
|
+
computeEnvironment: options?.batchComputeEnvironment ||
|
|
41742
|
+
this.awsSettings.defaultFargateBatchComputeEnvironment,
|
|
41743
|
+
order: 0,
|
|
41744
|
+
},
|
|
41745
|
+
],
|
|
41746
|
+
}));
|
|
41747
|
+
}
|
|
41748
|
+
async updateQueue(queueName, options) {
|
|
41749
|
+
if (!this.awsSettings.defaultFargateBatchComputeEnvironment &&
|
|
41750
|
+
!options?.batchComputeEnvironment) {
|
|
41751
|
+
throw new Error(`No compute environment defined`);
|
|
41752
|
+
}
|
|
41753
|
+
await this.client().send(new UpdateJobQueueCommand({
|
|
41754
|
+
jobQueue: queueName,
|
|
41755
|
+
priority: 0,
|
|
41756
|
+
computeEnvironmentOrder: [
|
|
41757
|
+
{
|
|
41758
|
+
computeEnvironment: options?.batchComputeEnvironment ||
|
|
41759
|
+
this.awsSettings.defaultFargateBatchComputeEnvironment,
|
|
41702
41760
|
order: 0,
|
|
41703
41761
|
},
|
|
41704
41762
|
],
|
|
@@ -41743,11 +41801,13 @@ let AwsJobsProvider = class AwsJobsProvider {
|
|
|
41743
41801
|
const { definition, schedule, instanceId, payload, commandPlaceholders } = input;
|
|
41744
41802
|
const awsInvocationParams = schedule?.invocationOverrides ??
|
|
41745
41803
|
definition.invocationParams;
|
|
41804
|
+
const awsInfrastructureParams = definition.infrastructureParams;
|
|
41746
41805
|
await this.awsBatchService.submitJob({
|
|
41747
41806
|
instanceId,
|
|
41748
41807
|
jobUid: definition.uid,
|
|
41749
41808
|
overrides: {
|
|
41750
41809
|
command: awsInvocationParams.startCommand?.map((x) => replacePlaceholders(replacePayload(x, payload), commandPlaceholders)),
|
|
41810
|
+
batchComputeEnvironment: awsInfrastructureParams.batchComputeEnvironment,
|
|
41751
41811
|
},
|
|
41752
41812
|
});
|
|
41753
41813
|
}
|