Skip to content

Commit

Permalink
initialize metrics
Browse files Browse the repository at this point in the history
  • Loading branch information
sanoel committed Dec 2, 2024
1 parent 45ff94d commit 048c26d
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 1 deletion.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
43 changes: 43 additions & 0 deletions src/Service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
});
}

/**
Expand Down

0 comments on commit 048c26d

Please sign in to comment.