@punks/backend-entity-manager 0.0.472 → 0.0.473

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.
@@ -1,3 +1,4 @@
1
+ import { BatchJobVariables } from "../../../plugins/jobs/aws-batch/manager/types";
1
2
  import { JobDefinition, JobSchedule } from "./definition";
2
3
  export interface JobDispatchInput {
3
4
  definition: JobDefinition<unknown, unknown>;
@@ -5,6 +6,7 @@ export interface JobDispatchInput {
5
6
  instanceId: string;
6
7
  payload?: unknown;
7
8
  commandPlaceholders?: Record<string, string>;
9
+ variables?: BatchJobVariables;
8
10
  }
9
11
  export declare enum JobProviderState {
10
12
  Initializing = "initializing",
@@ -0,0 +1,4 @@
1
+ import { KeyValuePair } from "@aws-sdk/client-batch";
2
+ import { BatchJobVariables } from "./types";
3
+ export declare const replaceVariable: (environmentValue: KeyValuePair, variables: BatchJobVariables) => KeyValuePair;
4
+ export declare const replaceVariables: (environment: KeyValuePair[], variables: BatchJobVariables) => KeyValuePair[];
@@ -11,10 +11,12 @@ export type BatchJobOverrides = {
11
11
  command?: string[];
12
12
  batchComputeEnvironment?: string;
13
13
  };
14
+ export type BatchJobVariables = Record<string, string>;
14
15
  export type SubmitBatchJobInput = {
15
16
  overrides?: BatchJobOverrides;
16
17
  jobUid: string;
17
18
  instanceId: string;
19
+ variables?: BatchJobVariables;
18
20
  };
19
21
  export type GetBatchJobStatusInput = {
20
22
  jobUid: string;
package/dist/esm/index.js CHANGED
@@ -41506,6 +41506,27 @@ const ensureJobLogGroup = async (logGroupName, awsSettings) => {
41506
41506
  }
41507
41507
  };
41508
41508
 
41509
+ const replaceVariablesInValue = (value, variables) => {
41510
+ // Example matches:
41511
+ // Input: "Hello ${name} and $(user)!" with variables {name: "World", user: "John"}
41512
+ // Output: "Hello World and John!"
41513
+ //
41514
+ // Input: "The ${animal} jumps over $(object)" with variables {animal: "fox", object: "fence"}
41515
+ // Output: "The fox jumps over fence"
41516
+ return value.replace(/[\$][\{\(]([^\}\)]+)[\}\)]/g, (match, p1) => variables[p1]);
41517
+ };
41518
+ const replaceVariable = (environmentValue, variables) => {
41519
+ return {
41520
+ name: environmentValue.name,
41521
+ value: environmentValue.value
41522
+ ? replaceVariablesInValue(environmentValue.value, variables)
41523
+ : environmentValue.value,
41524
+ };
41525
+ };
41526
+ const replaceVariables = (environment, variables) => {
41527
+ return environment.map((e) => replaceVariable(e, variables));
41528
+ };
41529
+
41509
41530
  var AwsBatchService_1;
41510
41531
  const jobDefinitionName = (jobUid) => `${awsBatchSettings.value.batchResourcesPrefix}-job-${jobUid}`;
41511
41532
  const jobInstanceName = (jobUid, instanceId) => `${awsBatchSettings.value.batchResourcesPrefix}-job-${jobUid}-${instanceId}`;
@@ -41572,14 +41593,18 @@ let AwsBatchService = AwsBatchService_1 = class AwsBatchService {
41572
41593
  jobQueue: queue.jobQueueArn,
41573
41594
  jobDefinition: jobDefinition.jobDefinitionArn,
41574
41595
  jobName,
41575
- ...(input.overrides?.command || jobDefinition.containerProperties?.command
41576
- ? {
41577
- containerOverrides: {
41596
+ containerOverrides: {
41597
+ ...(input.overrides?.command ||
41598
+ jobDefinition.containerProperties?.command
41599
+ ? {
41578
41600
  command: input.overrides?.command ??
41579
41601
  jobDefinition.containerProperties.command,
41580
- },
41581
- }
41582
- : {}),
41602
+ }
41603
+ : {}),
41604
+ environment: jobDefinition.containerProperties?.environment && input.variables
41605
+ ? replaceVariables(jobDefinition.containerProperties.environment, input.variables)
41606
+ : jobDefinition.containerProperties?.environment ?? [],
41607
+ },
41583
41608
  };
41584
41609
  this.logger.info(`AWS JOB -> invoking job ${jobName} ${queue.jobQueueArn}`, {
41585
41610
  request: submitJobRequest,
@@ -41711,6 +41736,8 @@ let AwsBatchService = AwsBatchService_1 = class AwsBatchService {
41711
41736
  });
41712
41737
  await this.updateQueue(queueName, options);
41713
41738
  this.logger.debug(`AWS JOB -> queue updated ${queueName}`);
41739
+ // Wait for the queue to be active
41740
+ await sleep(10000);
41714
41741
  const updatedQueue = await this.getQueue(queueName);
41715
41742
  if (!updatedQueue) {
41716
41743
  throw new Error(`Queue not updated -> ${queueName}`);
@@ -41809,6 +41836,7 @@ let AwsJobsProvider = class AwsJobsProvider {
41809
41836
  command: awsInvocationParams.startCommand?.map((x) => replacePlaceholders(replacePayload(x, payload), commandPlaceholders)),
41810
41837
  batchComputeEnvironment: awsInfrastructureParams.batchComputeEnvironment,
41811
41838
  },
41839
+ variables: input.variables,
41812
41840
  });
41813
41841
  }
41814
41842
  async upsertJobDefinition(input) {