From 048c26de87395c7d233e597141e0a4d7b1140e69 Mon Sep 17 00:00:00 2001 From: Sam Noel Date: Mon, 2 Dec 2024 14:15:36 -0500 Subject: [PATCH] initialize metrics --- package.json | 2 +- src/Service.ts | 43 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 44 insertions(+), 1 deletion(-) 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', + }); } /**