@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 CHANGED
@@ -41563,9 +41563,25 @@ let AwsBatchService = AwsBatchService_1 = class AwsBatchService {
41563
41563
  this.logger.info(`AWS JOB -> submitting job triggered`, {
41564
41564
  input,
41565
41565
  });
41566
- const queue = await this.ensureQueue(jobQueueName(input.jobUid));
41567
41566
  const jobDefName = jobDefinitionName(input.jobUid);
41568
41567
  const jobDefinition = await this.getLatestJobDefinition(jobDefName);
41568
+ if (!jobDefinition) {
41569
+ throw new Error(`Job definition not found -> ${jobDefName}`);
41570
+ }
41571
+ const platformType = jobDefinition.platformCapabilities?.[0];
41572
+ if (!platformType) {
41573
+ throw new Error(`Platform type not found -> ${jobDefName}`);
41574
+ }
41575
+ const defaultComputeEnvironment = platformType === clientBatch.PlatformCapability.FARGATE
41576
+ ? this.awsSettings.defaultFargateBatchComputeEnvironment
41577
+ : this.awsSettings.defaultEc2BatchComputeEnvironment;
41578
+ const batchComputeEnvironment = input.overrides?.batchComputeEnvironment ?? defaultComputeEnvironment;
41579
+ if (!batchComputeEnvironment) {
41580
+ throw new Error(`Compute environment not found -> ${jobDefName}`);
41581
+ }
41582
+ const queue = await this.ensureQueue(jobQueueName(input.jobUid), {
41583
+ batchComputeEnvironment,
41584
+ });
41569
41585
  const jobName = jobInstanceName(input.jobUid, input.instanceId);
41570
41586
  const submitJobRequest = {
41571
41587
  jobQueue: queue.jobQueueArn,
@@ -41692,18 +41708,32 @@ let AwsBatchService = AwsBatchService_1 = class AwsBatchService {
41692
41708
  }));
41693
41709
  return result.jobDefinitions ?? [];
41694
41710
  }
41695
- async ensureQueue(queueName) {
41711
+ async ensureQueue(queueName, options) {
41696
41712
  if (!queueName) {
41697
41713
  throw new Error(`Queue name not provided`);
41698
41714
  }
41699
41715
  this.logger.debug(`AWS JOB -> ensuring queue ${queueName}`);
41700
41716
  const queue = await this.getQueue(queueName);
41701
41717
  if (queue) {
41702
- this.logger.debug(`AWS JOB -> queue exists ${queueName}`);
41703
- return queue;
41718
+ if (queue.computeEnvironmentOrder?.[0].computeEnvironment ===
41719
+ options.batchComputeEnvironment) {
41720
+ this.logger.debug(`AWS JOB -> queue exists ${queueName}`);
41721
+ return queue;
41722
+ }
41723
+ this.logger.debug(`AWS JOB -> queue exists with different compute environment ${queueName}`, {
41724
+ queue,
41725
+ options,
41726
+ });
41727
+ await this.updateQueue(queueName, options);
41728
+ this.logger.debug(`AWS JOB -> queue updated ${queueName}`);
41729
+ const updatedQueue = await this.getQueue(queueName);
41730
+ if (!updatedQueue) {
41731
+ throw new Error(`Queue not updated -> ${queueName}`);
41732
+ }
41733
+ return updatedQueue;
41704
41734
  }
41705
41735
  this.logger.debug(`AWS JOB -> creating queue ${queueName}`);
41706
- await this.createQueue(queueName);
41736
+ await this.createQueue(queueName, options);
41707
41737
  this.logger.debug(`AWS JOB -> queue created ${queueName}`);
41708
41738
  // Wait for the queue to be active
41709
41739
  await backendCore.sleep(10000);
@@ -41713,8 +41743,9 @@ let AwsBatchService = AwsBatchService_1 = class AwsBatchService {
41713
41743
  }
41714
41744
  return currentQueue;
41715
41745
  }
41716
- async createQueue(queueName) {
41717
- if (!this.awsSettings.batchComputeEnvironment) {
41746
+ async createQueue(queueName, options) {
41747
+ if (!this.awsSettings.defaultFargateBatchComputeEnvironment &&
41748
+ !options?.batchComputeEnvironment) {
41718
41749
  throw new Error(`No compute environment defined`);
41719
41750
  }
41720
41751
  await this.client().send(new clientBatch.CreateJobQueueCommand({
@@ -41722,7 +41753,25 @@ let AwsBatchService = AwsBatchService_1 = class AwsBatchService {
41722
41753
  priority: 0,
41723
41754
  computeEnvironmentOrder: [
41724
41755
  {
41725
- computeEnvironment: this.awsSettings.batchComputeEnvironment,
41756
+ computeEnvironment: options?.batchComputeEnvironment ||
41757
+ this.awsSettings.defaultFargateBatchComputeEnvironment,
41758
+ order: 0,
41759
+ },
41760
+ ],
41761
+ }));
41762
+ }
41763
+ async updateQueue(queueName, options) {
41764
+ if (!this.awsSettings.defaultFargateBatchComputeEnvironment &&
41765
+ !options?.batchComputeEnvironment) {
41766
+ throw new Error(`No compute environment defined`);
41767
+ }
41768
+ await this.client().send(new clientBatch.UpdateJobQueueCommand({
41769
+ jobQueue: queueName,
41770
+ priority: 0,
41771
+ computeEnvironmentOrder: [
41772
+ {
41773
+ computeEnvironment: options?.batchComputeEnvironment ||
41774
+ this.awsSettings.defaultFargateBatchComputeEnvironment,
41726
41775
  order: 0,
41727
41776
  },
41728
41777
  ],
@@ -41767,11 +41816,13 @@ let AwsJobsProvider = class AwsJobsProvider {
41767
41816
  const { definition, schedule, instanceId, payload, commandPlaceholders } = input;
41768
41817
  const awsInvocationParams = schedule?.invocationOverrides ??
41769
41818
  definition.invocationParams;
41819
+ const awsInfrastructureParams = definition.infrastructureParams;
41770
41820
  await this.awsBatchService.submitJob({
41771
41821
  instanceId,
41772
41822
  jobUid: definition.uid,
41773
41823
  overrides: {
41774
41824
  command: awsInvocationParams.startCommand?.map((x) => replacePlaceholders(replacePayload(x, payload), commandPlaceholders)),
41825
+ batchComputeEnvironment: awsInfrastructureParams.batchComputeEnvironment,
41775
41826
  },
41776
41827
  });
41777
41828
  }