@punks/backend-entity-manager 0.0.471 → 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 +59 -8
- package/dist/cjs/index.js.map +1 -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 +60 -9
- package/dist/esm/index.js.map +1 -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 +3 -1
- package/package.json +3 -3
|
@@ -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';
|
|
@@ -41548,9 +41548,25 @@ let AwsBatchService = AwsBatchService_1 = class AwsBatchService {
|
|
|
41548
41548
|
this.logger.info(`AWS JOB -> submitting job triggered`, {
|
|
41549
41549
|
input,
|
|
41550
41550
|
});
|
|
41551
|
-
const queue = await this.ensureQueue(jobQueueName(input.jobUid));
|
|
41552
41551
|
const jobDefName = jobDefinitionName(input.jobUid);
|
|
41553
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
|
+
});
|
|
41554
41570
|
const jobName = jobInstanceName(input.jobUid, input.instanceId);
|
|
41555
41571
|
const submitJobRequest = {
|
|
41556
41572
|
jobQueue: queue.jobQueueArn,
|
|
@@ -41677,18 +41693,32 @@ let AwsBatchService = AwsBatchService_1 = class AwsBatchService {
|
|
|
41677
41693
|
}));
|
|
41678
41694
|
return result.jobDefinitions ?? [];
|
|
41679
41695
|
}
|
|
41680
|
-
async ensureQueue(queueName) {
|
|
41696
|
+
async ensureQueue(queueName, options) {
|
|
41681
41697
|
if (!queueName) {
|
|
41682
41698
|
throw new Error(`Queue name not provided`);
|
|
41683
41699
|
}
|
|
41684
41700
|
this.logger.debug(`AWS JOB -> ensuring queue ${queueName}`);
|
|
41685
41701
|
const queue = await this.getQueue(queueName);
|
|
41686
41702
|
if (queue) {
|
|
41687
|
-
|
|
41688
|
-
|
|
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;
|
|
41689
41719
|
}
|
|
41690
41720
|
this.logger.debug(`AWS JOB -> creating queue ${queueName}`);
|
|
41691
|
-
await this.createQueue(queueName);
|
|
41721
|
+
await this.createQueue(queueName, options);
|
|
41692
41722
|
this.logger.debug(`AWS JOB -> queue created ${queueName}`);
|
|
41693
41723
|
// Wait for the queue to be active
|
|
41694
41724
|
await sleep(10000);
|
|
@@ -41698,8 +41728,9 @@ let AwsBatchService = AwsBatchService_1 = class AwsBatchService {
|
|
|
41698
41728
|
}
|
|
41699
41729
|
return currentQueue;
|
|
41700
41730
|
}
|
|
41701
|
-
async createQueue(queueName) {
|
|
41702
|
-
if (!this.awsSettings.
|
|
41731
|
+
async createQueue(queueName, options) {
|
|
41732
|
+
if (!this.awsSettings.defaultFargateBatchComputeEnvironment &&
|
|
41733
|
+
!options?.batchComputeEnvironment) {
|
|
41703
41734
|
throw new Error(`No compute environment defined`);
|
|
41704
41735
|
}
|
|
41705
41736
|
await this.client().send(new CreateJobQueueCommand({
|
|
@@ -41707,7 +41738,25 @@ let AwsBatchService = AwsBatchService_1 = class AwsBatchService {
|
|
|
41707
41738
|
priority: 0,
|
|
41708
41739
|
computeEnvironmentOrder: [
|
|
41709
41740
|
{
|
|
41710
|
-
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,
|
|
41711
41760
|
order: 0,
|
|
41712
41761
|
},
|
|
41713
41762
|
],
|
|
@@ -41752,11 +41801,13 @@ let AwsJobsProvider = class AwsJobsProvider {
|
|
|
41752
41801
|
const { definition, schedule, instanceId, payload, commandPlaceholders } = input;
|
|
41753
41802
|
const awsInvocationParams = schedule?.invocationOverrides ??
|
|
41754
41803
|
definition.invocationParams;
|
|
41804
|
+
const awsInfrastructureParams = definition.infrastructureParams;
|
|
41755
41805
|
await this.awsBatchService.submitJob({
|
|
41756
41806
|
instanceId,
|
|
41757
41807
|
jobUid: definition.uid,
|
|
41758
41808
|
overrides: {
|
|
41759
41809
|
command: awsInvocationParams.startCommand?.map((x) => replacePlaceholders(replacePayload(x, payload), commandPlaceholders)),
|
|
41810
|
+
batchComputeEnvironment: awsInfrastructureParams.batchComputeEnvironment,
|
|
41760
41811
|
},
|
|
41761
41812
|
});
|
|
41762
41813
|
}
|