feat: emit started/stopped event on worker set
authorJérôme Benoit <jerome.benoit@sap.com>
Tue, 3 Oct 2023 09:26:38 +0000 (11:26 +0200)
committerJérôme Benoit <jerome.benoit@sap.com>
Tue, 3 Oct 2023 09:26:38 +0000 (11:26 +0200)
Signed-off-by: Jérôme Benoit <jerome.benoit@sap.com>
src/worker/WorkerSet.ts
src/worker/WorkerTypes.ts

index 5f10f090eea99788893736243c32ced43f7958fd..c5df860ced4fc85b16e7067c805605b05db75e04 100644 (file)
@@ -78,6 +78,7 @@ export class WorkerSet extends WorkerAbstract<WorkerData> {
     // Add worker set element sequentially to optimize memory at startup
     this.workerOptions.workerStartDelay! > 0 &&
       (await sleep(randomizeDelay(this.workerOptions.workerStartDelay!)));
+    this.emitter?.emit(WorkerSetEvents.started, this.info);
     this.started = true;
   }
 
@@ -92,6 +93,7 @@ export class WorkerSet extends WorkerAbstract<WorkerData> {
       });
       await worker.terminate();
       await waitWorkerExit;
+      this.emitter?.emit(WorkerSetEvents.stopped, this.info);
       this.emitter?.emitDestroy();
       this.started = false;
     }
index 806808d8a6fb020d2be7414b8d3848097de883bf..cfbe2dacb3b71cb9d6b755eb829468363454da62 100644 (file)
@@ -19,6 +19,8 @@ export interface SetInfo {
 }
 
 export enum WorkerSetEvents {
+  started = 'started',
+  stopped = 'stopped',
   error = 'error',
   elementStarted = 'elementStarted',
   elementError = 'elementError',