diff --git a/package.json b/package.json index bc9dc73..6adb647 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@oada/jobs", - "version": "4.7.3", + "version": "4.7.4", "description": "A library for oada job based microservices", "source": "src/index.ts", "main": "dist/index.js", diff --git a/src/Service.ts b/src/Service.ts index f61bbbc..9d1178a 100644 --- a/src/Service.ts +++ b/src/Service.ts @@ -230,6 +230,49 @@ export class Service { */ public on(type: string, timeout: number, work: WorkerFunction): void { this.#workers.set(type, { work, timeout }); + // Initialize the jobs metrics + this.metrics.jobs.set( + { + service: this.name, + type, + state: 'queued', + }, + 0, + ); + this.metrics.jobs.set( + { + service: this.name, + type, + state: 'running', + }, + 0, + ); + this.metrics.jobs.set( + { + service: this.name, + type, + state: 'success', + }, + 0, + ); + this.metrics.jobs.set( + { + service: this.name, + type, + state: 'failure', + }, + 0, + ); + this.metrics['job-times'].zero({ + service: this.name, + type, + status: 'success', + }); + this.metrics['job-times'].zero({ + service: this.name, + type, + status: 'failure', + }); } /**