@punks/backend-entity-manager 0.0.310 → 0.0.312

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.
@@ -4,6 +4,7 @@ export interface JobDispatchInput {
4
4
  schedule?: JobSchedule<unknown>;
5
5
  instanceId: string;
6
6
  payload?: unknown;
7
+ commandPlaceholders?: Record<string, string>;
7
8
  }
8
9
  export declare enum JobProviderState {
9
10
  Initializing = "initializing",
@@ -4,6 +4,7 @@ export interface JobDispatchCommandInput {
4
4
  schedule?: JobSchedule<unknown>;
5
5
  runType: JobRunType;
6
6
  payload?: unknown;
7
+ commandPlaceholders?: Record<string, string>;
7
8
  }
8
9
  export declare class JobDispatchCommand {
9
10
  readonly input: JobDispatchCommandInput;
@@ -2,4 +2,5 @@ export type JobTriggerInput = {
2
2
  jobUid: string;
3
3
  scheduleUid?: string;
4
4
  payload?: any;
5
+ commandPlaceholders?: Record<string, string>;
5
6
  };
package/dist/esm/index.js CHANGED
@@ -33863,6 +33863,7 @@ let JobsService = class JobsService {
33863
33863
  schedule,
33864
33864
  runType: JobRunType.OnDemand,
33865
33865
  payload: input.payload,
33866
+ commandPlaceholders: input.commandPlaceholders,
33866
33867
  }));
33867
33868
  };
33868
33869
  this.updateJob = async (input) => {
@@ -33963,7 +33964,7 @@ let JobDispatchHandler = JobDispatchHandler_1 = class JobDispatchHandler {
33963
33964
  return result.result;
33964
33965
  }
33965
33966
  async dispatchJob(command) {
33966
- const { input: { job, schedule, runType, payload }, } = command;
33967
+ const { input: { job, schedule, runType, payload, commandPlaceholders }, } = command;
33967
33968
  const instanceId = newUuid$1();
33968
33969
  try {
33969
33970
  this.logger.info(`JOB DISPATCH -> dispatching started job ${job.uid} -> ${instanceId}`);
@@ -33978,6 +33979,7 @@ let JobDispatchHandler = JobDispatchHandler_1 = class JobDispatchHandler {
33978
33979
  schedule,
33979
33980
  instanceId,
33980
33981
  payload,
33982
+ commandPlaceholders,
33981
33983
  });
33982
33984
  await this.instances.updateInstance(instanceId, {
33983
33985
  status: JobStatus.Ready,
@@ -40231,18 +40233,20 @@ const mapJobStatus = (awsJobStatus) => {
40231
40233
  return JobProviderState.Completed;
40232
40234
  }
40233
40235
  };
40236
+ const replacePayload = (command, payload) => command.replaceAll("$(payload)", JSON.stringify(payload ?? {}));
40237
+ const replacePlaceholders = (command, placeholders) => Object.entries(placeholders ?? {}).reduce((acc, [key, value]) => acc.replaceAll(`$(${key})`, value), command);
40234
40238
  let AwsJobsProvider = class AwsJobsProvider {
40235
40239
  constructor(awsBatchService) {
40236
40240
  this.awsBatchService = awsBatchService;
40237
40241
  }
40238
40242
  async dispatch(input) {
40239
- const { definition, schedule, instanceId, payload } = input;
40243
+ const { definition, schedule, instanceId, payload, commandPlaceholders } = input;
40240
40244
  const awsInvocationParams = schedule?.invocationOverrides;
40241
40245
  await this.awsBatchService.submitJob({
40242
40246
  instanceId,
40243
40247
  jobUid: definition.uid,
40244
40248
  overrides: {
40245
- command: awsInvocationParams?.startCommand?.map((x) => x.replace("{payload}", JSON.stringify(payload ?? {}))),
40249
+ command: awsInvocationParams?.startCommand?.map((x) => replacePlaceholders(replacePayload(x, payload), commandPlaceholders)),
40246
40250
  },
40247
40251
  });
40248
40252
  }