@punks/backend-entity-manager 0.0.270 → 0.0.272

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.
@@ -2,17 +2,17 @@ import { JobDefinition } from "./definition";
2
2
  import { JobInstance, JobStatus } from "./instance";
3
3
  type JobData = Omit<JobDefinition<unknown, unknown>, "id" | "createdOn" | "updatedOn">;
4
4
  export interface IJobDefinitionsRepository {
5
- all(): Promise<JobDefinition<unknown, unknown>[]>;
6
- getByUid(uid: string): Promise<JobDefinition<unknown, unknown> | undefined>;
7
- ensure(data: JobData): Promise<JobDefinition<unknown, unknown>>;
8
- create(data: JobData): Promise<JobDefinition<unknown, unknown>>;
9
- update(uid: string, data: JobData): Promise<JobDefinition<unknown, unknown>>;
5
+ getAllDefinitions(): Promise<JobDefinition<unknown, unknown>[]>;
6
+ getDefinitionByUid(uid: string): Promise<JobDefinition<unknown, unknown> | undefined>;
7
+ ensureDefinition(data: JobData): Promise<JobDefinition<unknown, unknown>>;
8
+ createDefinition(data: JobData): Promise<JobDefinition<unknown, unknown>>;
9
+ updateDefinition(uid: string, data: JobData): Promise<JobDefinition<unknown, unknown>>;
10
10
  }
11
11
  export interface IJobInstancesRepository {
12
- get(id: string): Promise<JobInstance>;
12
+ getById(id: string): Promise<JobInstance>;
13
13
  getByStatus(...status: JobStatus[]): Promise<JobInstance[]>;
14
14
  getLastInstance(jobUid: string, scheduleUid: string): Promise<JobInstance | undefined>;
15
- append(job: JobDefinition<unknown, unknown>, data: Pick<JobInstance, "id" | "insertTime" | "scheduleUid" | "runType">): Promise<JobInstance>;
16
- update(instanceId: string, data: Pick<JobInstance, "startTime" | "endTime" | "status" | "result" | "error">): Promise<JobInstance>;
15
+ appendInstance(job: JobDefinition<unknown, unknown>, data: Pick<JobInstance, "id" | "insertTime" | "scheduleUid" | "runType">): Promise<JobInstance>;
16
+ updateInstance(instanceId: string, data: Pick<JobInstance, "startTime" | "endTime" | "status" | "result" | "error">): Promise<JobInstance>;
17
17
  }
18
18
  export {};
@@ -1,7 +1,10 @@
1
- import { OnModuleInit } from "@nestjs/common";
1
+ import { DynamicModule, OnModuleInit, Type } from "@nestjs/common";
2
2
  import { EntityManagerRegistry } from "./ioc/registry";
3
3
  export declare class EntityManagerModule implements OnModuleInit {
4
4
  private readonly registry;
5
5
  constructor(registry: EntityManagerRegistry);
6
6
  onModuleInit(): void;
7
+ static forRoot(providers: {
8
+ operationsLockRepository: Type<unknown>;
9
+ }): DynamicModule;
7
10
  }
package/dist/esm/index.js CHANGED
@@ -23613,6 +23613,7 @@ const getIoCContext = () => {
23613
23613
  return _context;
23614
23614
  };
23615
23615
 
23616
+ var EntityManagerModule_1;
23616
23617
  const ModuleData$9 = {
23617
23618
  imports: [CustomDiscoveryModule, EventEmitterModule],
23618
23619
  providers: [
@@ -23624,7 +23625,7 @@ const ModuleData$9 = {
23624
23625
  ],
23625
23626
  exports: [EntityManagerRegistry, ...Services$1],
23626
23627
  };
23627
- let EntityManagerModule = class EntityManagerModule {
23628
+ let EntityManagerModule = EntityManagerModule_1 = class EntityManagerModule {
23628
23629
  constructor(registry) {
23629
23630
  this.registry = registry;
23630
23631
  }
@@ -23633,8 +23634,21 @@ let EntityManagerModule = class EntityManagerModule {
23633
23634
  registry: this.registry,
23634
23635
  });
23635
23636
  }
23637
+ static forRoot(providers) {
23638
+ return {
23639
+ module: EntityManagerModule_1,
23640
+ ...ModuleData$9,
23641
+ providers: [
23642
+ ...ModuleData$9.providers,
23643
+ {
23644
+ provide: getEntityManagerProviderToken("OperationsLockRepository"),
23645
+ useClass: providers.operationsLockRepository,
23646
+ },
23647
+ ],
23648
+ };
23649
+ }
23636
23650
  };
23637
- EntityManagerModule = __decorate([
23651
+ EntityManagerModule = EntityManagerModule_1 = __decorate([
23638
23652
  Module({
23639
23653
  imports: ModuleData$9.imports,
23640
23654
  providers: ModuleData$9.providers,
@@ -33672,7 +33686,7 @@ let JobsSchedulerTask = JobsSchedulerTask_1 = class JobsSchedulerTask {
33672
33686
  }
33673
33687
  async run() {
33674
33688
  this.logger.info(`JobsSchedulerTask -> run start`);
33675
- const jobs = await this.jobDefinitions.all();
33689
+ const jobs = await this.jobDefinitions.getAllDefinitions();
33676
33690
  for (const job of jobs) {
33677
33691
  await this.evaluateJob(job);
33678
33692
  }
@@ -33747,7 +33761,7 @@ let JobsMonitorTask = JobsMonitorTask_1 = class JobsMonitorTask {
33747
33761
  async monitorInstance(instance) {
33748
33762
  try {
33749
33763
  this.logger.info(`JobsMonitorTask -> evaluating job ${instance.id}`);
33750
- const job = await this.jobDefinitions.getByUid(instance.jobUid);
33764
+ const job = await this.jobDefinitions.getDefinitionByUid(instance.jobUid);
33751
33765
  if (!job) {
33752
33766
  throw new Error(`Job definition not found -> ${instance.jobUid}`);
33753
33767
  }
@@ -33889,7 +33903,7 @@ let JobDispatchHandler = JobDispatchHandler_1 = class JobDispatchHandler {
33889
33903
  const instanceId = newUuid$1();
33890
33904
  try {
33891
33905
  this.logger.info(`JOB DISPATCH -> dispatching started job ${job.uid} -> ${instanceId}`);
33892
- await this.instances.append(job, {
33906
+ await this.instances.appendInstance(job, {
33893
33907
  id: instanceId,
33894
33908
  runType,
33895
33909
  scheduleUid: schedule.uid,
@@ -33900,13 +33914,13 @@ let JobDispatchHandler = JobDispatchHandler_1 = class JobDispatchHandler {
33900
33914
  schedule,
33901
33915
  instanceId,
33902
33916
  });
33903
- await this.instances.update(instanceId, {
33917
+ await this.instances.updateInstance(instanceId, {
33904
33918
  status: JobStatus.Ready,
33905
33919
  });
33906
33920
  this.logger.info(`JOB DISPATCH -> dispatching completed job ${job.uid} -> ${instanceId}`);
33907
33921
  }
33908
33922
  catch (e) {
33909
- await this.instances.update(instanceId, {
33923
+ await this.instances.updateInstance(instanceId, {
33910
33924
  status: JobStatus.InitializationError,
33911
33925
  error: `${e.message} -> \n\n ${e.stack}`,
33912
33926
  });
@@ -33952,7 +33966,7 @@ let JobStatusMonitorHandler = JobStatusMonitorHandler_1 = class JobStatusMonitor
33952
33966
  const { input: { job, instanceId }, } = command;
33953
33967
  try {
33954
33968
  this.logger.info(`JOB STATUS UPDATE -> dispatching started job ${job.uid} -> ${instanceId}`);
33955
- const current = await this.instances.get(instanceId);
33969
+ const current = await this.instances.getById(instanceId);
33956
33970
  if (!current) {
33957
33971
  throw new Error(`Job instance ${instanceId} not found`);
33958
33972
  }
@@ -33968,7 +33982,7 @@ let JobStatusMonitorHandler = JobStatusMonitorHandler_1 = class JobStatusMonitor
33968
33982
  this.logger.info(`JOB STATUS UPDATE -> status unchanged ${job.uid} -> ${instanceId}`);
33969
33983
  return;
33970
33984
  }
33971
- await this.instances.update(instanceId, {
33985
+ await this.instances.updateInstance(instanceId, {
33972
33986
  status: newStatus,
33973
33987
  endTime: !current.endTime && isJobEnded(newStatus) ? new Date() : undefined,
33974
33988
  startTime: !current.startTime && isJobStarted(newStatus)
@@ -34016,7 +34030,7 @@ let JobDefinitionUpdateHandler = JobDefinitionUpdateHandler_1 = class JobDefinit
34016
34030
  await this.executor.upsertJobDefinition({
34017
34031
  definition: job,
34018
34032
  });
34019
- await this.definitions.ensure(job);
34033
+ await this.definitions.ensureDefinition(job);
34020
34034
  this.logger.info(`JOB DEFINITION UPDATE -> status update completed job ${job.uid}`);
34021
34035
  }
34022
34036
  };