@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.
@@ -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",
@@ -1,3 +1,4 @@
1
+ import { BatchJobVariables } from "../../../../plugins/jobs/aws-batch/manager/types";
1
2
  import { JobDefinition, JobRunType, JobSchedule } from "../../abstractions";
2
3
  export interface JobDispatchCommandInput {
3
4
  job: JobDefinition<unknown, unknown>;
@@ -5,6 +6,7 @@ export interface JobDispatchCommandInput {
5
6
  runType: JobRunType;
6
7
  payload?: unknown;
7
8
  commandPlaceholders?: Record<string, string>;
9
+ variables?: BatchJobVariables;
8
10
  }
9
11
  export declare class JobDispatchCommand {
10
12
  readonly input: JobDispatchCommandInput;
@@ -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
@@ -34912,7 +34912,7 @@ let JobDispatchHandler = JobDispatchHandler_1 = class JobDispatchHandler {
34912
34912
  return result.result;
34913
34913
  }
34914
34914
  async dispatchJob(command) {
34915
- const { input: { job, schedule, runType, payload, commandPlaceholders }, } = command;
34915
+ const { input: { job, schedule, runType, payload, commandPlaceholders, variables, }, } = command;
34916
34916
  const instanceId = newUuid$1();
34917
34917
  try {
34918
34918
  this.logger.info(`JOB DISPATCH -> dispatching started job ${job.uid} -> ${instanceId}`);
@@ -34928,6 +34928,7 @@ let JobDispatchHandler = JobDispatchHandler_1 = class JobDispatchHandler {
34928
34928
  instanceId,
34929
34929
  payload,
34930
34930
  commandPlaceholders,
34931
+ variables,
34931
34932
  });
34932
34933
  await this.instances.updateInstance(instanceId, {
34933
34934
  status: JobStatus.Ready,
@@ -41506,6 +41507,27 @@ const ensureJobLogGroup = async (logGroupName, awsSettings) => {
41506
41507
  }
41507
41508
  };
41508
41509
 
41510
+ const replaceVariablesInValue = (value, variables) => {
41511
+ // Example matches:
41512
+ // Input: "Hello ${name} and $(user)!" with variables {name: "World", user: "John"}
41513
+ // Output: "Hello World and John!"
41514
+ //
41515
+ // Input: "The ${animal} jumps over $(object)" with variables {animal: "fox", object: "fence"}
41516
+ // Output: "The fox jumps over fence"
41517
+ return value.replace(/[\$][\{\(]([^\}\)]+)[\}\)]/g, (match, p1) => variables[p1]);
41518
+ };
41519
+ const replaceVariable = (environmentValue, variables) => {
41520
+ return {
41521
+ name: environmentValue.name,
41522
+ value: environmentValue.value
41523
+ ? replaceVariablesInValue(environmentValue.value, variables)
41524
+ : environmentValue.value,
41525
+ };
41526
+ };
41527
+ const replaceVariables = (environment, variables) => {
41528
+ return environment.map((e) => replaceVariable(e, variables));
41529
+ };
41530
+
41509
41531
  var AwsBatchService_1;
41510
41532
  const jobDefinitionName = (jobUid) => `${awsBatchSettings.value.batchResourcesPrefix}-job-${jobUid}`;
41511
41533
  const jobInstanceName = (jobUid, instanceId) => `${awsBatchSettings.value.batchResourcesPrefix}-job-${jobUid}-${instanceId}`;
@@ -41572,14 +41594,18 @@ let AwsBatchService = AwsBatchService_1 = class AwsBatchService {
41572
41594
  jobQueue: queue.jobQueueArn,
41573
41595
  jobDefinition: jobDefinition.jobDefinitionArn,
41574
41596
  jobName,
41575
- ...(input.overrides?.command || jobDefinition.containerProperties?.command
41576
- ? {
41577
- containerOverrides: {
41597
+ containerOverrides: {
41598
+ ...(input.overrides?.command ||
41599
+ jobDefinition.containerProperties?.command
41600
+ ? {
41578
41601
  command: input.overrides?.command ??
41579
41602
  jobDefinition.containerProperties.command,
41580
- },
41581
- }
41582
- : {}),
41603
+ }
41604
+ : {}),
41605
+ environment: jobDefinition.containerProperties?.environment && input.variables
41606
+ ? replaceVariables(jobDefinition.containerProperties.environment, input.variables)
41607
+ : jobDefinition.containerProperties?.environment ?? [],
41608
+ },
41583
41609
  };
41584
41610
  this.logger.info(`AWS JOB -> invoking job ${jobName} ${queue.jobQueueArn}`, {
41585
41611
  request: submitJobRequest,
@@ -41711,6 +41737,8 @@ let AwsBatchService = AwsBatchService_1 = class AwsBatchService {
41711
41737
  });
41712
41738
  await this.updateQueue(queueName, options);
41713
41739
  this.logger.debug(`AWS JOB -> queue updated ${queueName}`);
41740
+ // Wait for the queue to be active
41741
+ await sleep(10000);
41714
41742
  const updatedQueue = await this.getQueue(queueName);
41715
41743
  if (!updatedQueue) {
41716
41744
  throw new Error(`Queue not updated -> ${queueName}`);
@@ -41809,6 +41837,7 @@ let AwsJobsProvider = class AwsJobsProvider {
41809
41837
  command: awsInvocationParams.startCommand?.map((x) => replacePlaceholders(replacePayload(x, payload), commandPlaceholders)),
41810
41838
  batchComputeEnvironment: awsInfrastructureParams.batchComputeEnvironment,
41811
41839
  },
41840
+ variables: input.variables,
41812
41841
  });
41813
41842
  }
41814
41843
  async upsertJobDefinition(input) {