adding job counter metric
This commit is contained in:
parent
8867c79615
commit
aaf9614230
|
@ -25,7 +25,7 @@
|
|||
"timeout": 10000,
|
||||
"rateLimit": {
|
||||
"period": 10000,
|
||||
"limit": 40
|
||||
"limit": 20
|
||||
}
|
||||
},
|
||||
"ethereum": {
|
||||
|
|
|
@ -1,9 +1,12 @@
|
|||
import { setTimeout } from "timers/promises";
|
||||
import winston from "winston";
|
||||
import { Handler } from "../entities";
|
||||
import { StatRepository } from "../repositories";
|
||||
|
||||
export abstract class RunPollingJob {
|
||||
private interval: number;
|
||||
private id: string;
|
||||
private statRepo?: StatRepository;
|
||||
private running: boolean = false;
|
||||
protected abstract logger: winston.Logger;
|
||||
protected abstract preHook(): Promise<void>;
|
||||
|
@ -11,9 +14,11 @@ export abstract class RunPollingJob {
|
|||
protected abstract get(): Promise<any[]>;
|
||||
protected abstract persist(): Promise<void>;
|
||||
|
||||
constructor(interval: number) {
|
||||
constructor(interval: number, id: string, statRepo?: StatRepository) {
|
||||
this.interval = interval;
|
||||
this.id = id;
|
||||
this.running = true;
|
||||
this.statRepo = statRepo;
|
||||
}
|
||||
|
||||
public async run(handlers: Handler[]): Promise<void> {
|
||||
|
@ -33,16 +38,19 @@ export abstract class RunPollingJob {
|
|||
await Promise.all(handlers.map((handler) => handler(items)));
|
||||
} catch (e: Error | any) {
|
||||
this.logger.error("Error processing items", e, e.stack);
|
||||
this.statRepo?.count("job_runs_total", { id: this.id, status: "error" });
|
||||
await setTimeout(this.interval);
|
||||
continue;
|
||||
}
|
||||
|
||||
await this.persist();
|
||||
this.statRepo?.count("job_runs_total", { id: this.id, status: "success" });
|
||||
await setTimeout(this.interval);
|
||||
}
|
||||
}
|
||||
|
||||
public async stop(): Promise<void> {
|
||||
this.running = false;
|
||||
this.statRepo?.count("job_runs_stopped", { id: this.id });
|
||||
}
|
||||
}
|
||||
|
|
|
@ -26,7 +26,7 @@ export class PollEvmLogs extends RunPollingJob {
|
|||
statsRepository: StatRepository,
|
||||
cfg: PollEvmLogsConfig
|
||||
) {
|
||||
super(cfg.interval ?? 1_000);
|
||||
super(cfg.interval ?? 1_000, cfg.id, statsRepository);
|
||||
this.blockRepo = blockRepo;
|
||||
this.metadataRepo = metadataRepo;
|
||||
this.statsRepository = statsRepository;
|
||||
|
|
|
@ -19,7 +19,7 @@ export class PollSolanaTransactions extends RunPollingJob {
|
|||
statsRepo: StatRepository,
|
||||
cfg: PollSolanaTransactionsConfig
|
||||
) {
|
||||
super(1_000);
|
||||
super(1_000, cfg.id, statsRepo);
|
||||
|
||||
this.metadataRepo = metadataRepo;
|
||||
this.slotRepository = slotRepo;
|
||||
|
|
Loading…
Reference in New Issue