Skip to content
This repository has been archived by the owner on Mar 24, 2023. It is now read-only.

Commit

Permalink
chore: Add backgroud transaction for BlockEmitter#pool
Browse files Browse the repository at this point in the history
  • Loading branch information
classicalliu committed Aug 26, 2021
1 parent 9a8a0a4 commit e289740
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions packages/api-server/src/block-emitter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@ import { Query } from "./db";
import { EventEmitter } from "events";
import { toApiNewHead } from "./db/types";

let newrelic: any = undefined;
if (envConfig.newRelicLicenseKey) {
newrelic = require("newrelic");
}

export class BlockEmitter {
private query: Query;
private isRunning: boolean;
Expand Down Expand Up @@ -62,6 +67,32 @@ export class BlockEmitter {
return timeout;
}

// add new relic background transaction
if (envConfig.newRelicLicenseKey) {
return newrelic.startBackgroundTransaction(
`BlockEmitter#pool`,
async () => {
newrelic.getTransaction();
try {
const min = this.currentTip;
const max = tip;
const blocks = await this.query.getBlocksByNumbers(min, max);
const newHeads = blocks.map((b) => toApiNewHead(b));
this.emitter.emit("newHeads", newHeads);
const logs = await this.query.getLogs({}, min + BigInt(1), max); // exclude min & include max;
this.emitter.emit("logs", logs);
this.currentTip = tip;

return timeout;
} catch (error) {
throw error;
} finally {
newrelic.endTransaction();
}
}
);
}

const min = this.currentTip;
const max = tip;
const blocks = await this.query.getBlocksByNumbers(min, max);
Expand Down

0 comments on commit e289740

Please sign in to comment.