@punks/backend-entity-manager 0.0.472 → 0.0.474

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
@@ -34927,7 +34927,7 @@ let JobDispatchHandler = JobDispatchHandler_1 = class JobDispatchHandler {
34927
34927
  return result.result;
34928
34928
  }
34929
34929
  async dispatchJob(command) {
34930
- const { input: { job, schedule, runType, payload, commandPlaceholders }, } = command;
34930
+ const { input: { job, schedule, runType, payload, commandPlaceholders, variables, }, } = command;
34931
34931
  const instanceId = backendCore.newUuid();
34932
34932
  try {
34933
34933
  this.logger.info(`JOB DISPATCH -> dispatching started job ${job.uid} -> ${instanceId}`);
@@ -34943,6 +34943,7 @@ let JobDispatchHandler = JobDispatchHandler_1 = class JobDispatchHandler {
34943
34943
  instanceId,
34944
34944
  payload,
34945
34945
  commandPlaceholders,
34946
+ variables,
34946
34947
  });
34947
34948
  await this.instances.updateInstance(instanceId, {
34948
34949
  status: exports.JobStatus.Ready,
@@ -41521,6 +41522,27 @@ const ensureJobLogGroup = async (logGroupName, awsSettings) => {
41521
41522
  }
41522
41523
  };
41523
41524
 
41525
+ const replaceVariablesInValue = (value, variables) => {
41526
+ // Example matches:
41527
+ // Input: "Hello ${name} and $(user)!" with variables {name: "World", user: "John"}
41528
+ // Output: "Hello World and John!"
41529
+ //
41530
+ // Input: "The ${animal} jumps over $(object)" with variables {animal: "fox", object: "fence"}
41531
+ // Output: "The fox jumps over fence"
41532
+ return value.replace(/[\$][\{\(]([^\}\)]+)[\}\)]/g, (match, p1) => variables[p1]);
41533
+ };
41534
+ const replaceVariable = (environmentValue, variables) => {
41535
+ return {
41536
+ name: environmentValue.name,
41537
+ value: environmentValue.value
41538
+ ? replaceVariablesInValue(environmentValue.value, variables)
41539
+ : environmentValue.value,
41540
+ };
41541
+ };
41542
+ const replaceVariables = (environment, variables) => {
41543
+ return environment.map((e) => replaceVariable(e, variables));
41544
+ };
41545
+
41524
41546
  var AwsBatchService_1;
41525
41547
  const jobDefinitionName = (jobUid) => `${awsBatchSettings.value.batchResourcesPrefix}-job-${jobUid}`;
41526
41548
  const jobInstanceName = (jobUid, instanceId) => `${awsBatchSettings.value.batchResourcesPrefix}-job-${jobUid}-${instanceId}`;
@@ -41587,14 +41609,18 @@ let AwsBatchService = AwsBatchService_1 = class AwsBatchService {
41587
41609
  jobQueue: queue.jobQueueArn,
41588
41610
  jobDefinition: jobDefinition.jobDefinitionArn,
41589
41611
  jobName,
41590
- ...(input.overrides?.command || jobDefinition.containerProperties?.command
41591
- ? {
41592
- containerOverrides: {
41612
+ containerOverrides: {
41613
+ ...(input.overrides?.command ||
41614
+ jobDefinition.containerProperties?.command
41615
+ ? {
41593
41616
  command: input.overrides?.command ??
41594
41617
  jobDefinition.containerProperties.command,
41595
- },
41596
- }
41597
- : {}),
41618
+ }
41619
+ : {}),
41620
+ environment: jobDefinition.containerProperties?.environment && input.variables
41621
+ ? replaceVariables(jobDefinition.containerProperties.environment, input.variables)
41622
+ : jobDefinition.containerProperties?.environment ?? [],
41623
+ },
41598
41624
  };
41599
41625
  this.logger.info(`AWS JOB -> invoking job ${jobName} ${queue.jobQueueArn}`, {
41600
41626
  request: submitJobRequest,
@@ -41726,6 +41752,8 @@ let AwsBatchService = AwsBatchService_1 = class AwsBatchService {
41726
41752
  });
41727
41753
  await this.updateQueue(queueName, options);
41728
41754
  this.logger.debug(`AWS JOB -> queue updated ${queueName}`);
41755
+ // Wait for the queue to be active
41756
+ await backendCore.sleep(10000);
41729
41757
  const updatedQueue = await this.getQueue(queueName);
41730
41758
  if (!updatedQueue) {
41731
41759
  throw new Error(`Queue not updated -> ${queueName}`);
@@ -41824,6 +41852,7 @@ let AwsJobsProvider = class AwsJobsProvider {
41824
41852
  command: awsInvocationParams.startCommand?.map((x) => replacePlaceholders(replacePayload(x, payload), commandPlaceholders)),
41825
41853
  batchComputeEnvironment: awsInfrastructureParams.batchComputeEnvironment,
41826
41854
  },
41855
+ variables: input.variables,
41827
41856
  });
41828
41857
  }
41829
41858
  async upsertJobDefinition(input) {