@punks/backend-entity-manager 0.0.282 → 0.0.283

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
@@ -33834,7 +33834,65 @@ JobsScheduler = JobsScheduler_1 = __decorate([
33834
33834
 
33835
33835
  const JobsProviders = [JobsScheduler];
33836
33836
 
33837
- const JobsServices = [];
33837
+ class JobDefinitionUpdateCommand {
33838
+ constructor(input) {
33839
+ this.input = input;
33840
+ }
33841
+ }
33842
+
33843
+ exports.JobsService = class JobsService {
33844
+ constructor(definitions, instances, commandBus) {
33845
+ this.definitions = definitions;
33846
+ this.instances = instances;
33847
+ this.commandBus = commandBus;
33848
+ this.triggerJob = async (input) => {
33849
+ const job = await this.definitions.getDefinitionByUid(input.jobUid);
33850
+ if (!job) {
33851
+ throw new Error(`Job ${input.jobUid} not found`);
33852
+ }
33853
+ const schedule = input.scheduleUid
33854
+ ? job.schedules.find((x) => x.uid === input.scheduleUid)
33855
+ : undefined;
33856
+ if (input.scheduleUid && !schedule) {
33857
+ throw new Error(`Job ${input.jobUid} schedule ${input.scheduleUid} not found`);
33858
+ }
33859
+ return await this.commandBus.execute(new JobDispatchCommand({
33860
+ job,
33861
+ schedule,
33862
+ runType: exports.JobRunType.OnDemand,
33863
+ payload: input.payload,
33864
+ }));
33865
+ };
33866
+ this.updateJob = async (input) => {
33867
+ this.commandBus.execute(new JobDefinitionUpdateCommand({
33868
+ job: input,
33869
+ }));
33870
+ };
33871
+ this.instanceMonitor = async (input) => {
33872
+ const { instanceId } = input;
33873
+ const instance = await this.instances.getById(instanceId);
33874
+ if (!instance) {
33875
+ throw new Error(`Job instance ${instanceId} not found`);
33876
+ }
33877
+ const job = await this.definitions.getDefinitionByUid(instance.jobUid);
33878
+ if (!job) {
33879
+ throw new Error(`Job definition ${instance.jobUid} not found`);
33880
+ }
33881
+ return await this.commandBus.execute(new JobStatusMonitorCommand({
33882
+ instanceId,
33883
+ job,
33884
+ }));
33885
+ };
33886
+ }
33887
+ };
33888
+ exports.JobsService = __decorate([
33889
+ common.Injectable(),
33890
+ __param(0, common.Inject(getEntityManagerProviderToken("JobDefinitionsRepository"))),
33891
+ __param(1, common.Inject(getEntityManagerProviderToken("JobInstancesRepository"))),
33892
+ __metadata("design:paramtypes", [Object, Object, cqrs.CommandBus])
33893
+ ], exports.JobsService);
33894
+
33895
+ const JobsServices = [exports.JobsService];
33838
33896
 
33839
33897
  const JOB_PROVIDER = Symbol.for("WP.JOB_PROVIDER");
33840
33898
 
@@ -33902,7 +33960,7 @@ let JobDispatchHandler = JobDispatchHandler_1 = class JobDispatchHandler {
33902
33960
  });
33903
33961
  }
33904
33962
  async dispatchJob(command) {
33905
- const { input: { job, schedule, runType }, } = command;
33963
+ const { input: { job, schedule, runType, payload }, } = command;
33906
33964
  const instanceId = backendCore.newUuid();
33907
33965
  try {
33908
33966
  this.logger.info(`JOB DISPATCH -> dispatching started job ${job.uid} -> ${instanceId}`);
@@ -33916,6 +33974,7 @@ let JobDispatchHandler = JobDispatchHandler_1 = class JobDispatchHandler {
33916
33974
  definition: job,
33917
33975
  schedule,
33918
33976
  instanceId,
33977
+ payload,
33919
33978
  });
33920
33979
  await this.instances.updateInstance(instanceId, {
33921
33980
  status: exports.JobStatus.Ready,
@@ -34006,12 +34065,6 @@ JobStatusMonitorHandler = JobStatusMonitorHandler_1 = __decorate([
34006
34065
  JobProviderExecutor, Object])
34007
34066
  ], JobStatusMonitorHandler);
34008
34067
 
34009
- class JobDefinitionUpdateCommand {
34010
- constructor(input) {
34011
- this.input = input;
34012
- }
34013
- }
34014
-
34015
34068
  var JobDefinitionUpdateHandler_1;
34016
34069
  let JobDefinitionUpdateHandler = JobDefinitionUpdateHandler_1 = class JobDefinitionUpdateHandler {
34017
34070
  constructor(lock, definitions, executor) {
@@ -40085,13 +40138,13 @@ let AwsJobsProvider = class AwsJobsProvider {
40085
40138
  this.awsBatchService = awsBatchService;
40086
40139
  }
40087
40140
  async dispatch(input) {
40088
- const { definition, schedule, instanceId } = input;
40141
+ const { definition, schedule, instanceId, payload } = input;
40089
40142
  const awsInvocationParams = schedule?.invocationOverrides;
40090
40143
  await this.awsBatchService.submitJob({
40091
40144
  instanceId,
40092
40145
  jobUid: definition.uid,
40093
40146
  overrides: {
40094
- command: awsInvocationParams?.startCommand,
40147
+ command: awsInvocationParams?.startCommand?.map((x) => x.replace("{payload}", JSON.stringify(payload ?? {}))),
40095
40148
  },
40096
40149
  });
40097
40150
  }