Skip to content

Commit db1a5a9

Browse files
authored
Updated Usage Report + MinedTxListener (#416)
* added check for root url on usage tracker. updated minedTxListener * updated implementation to skip usage reporting for some URLS * updates * updates * updates * updated sharedSchema
1 parent f71ca64 commit db1a5a9

File tree

2 files changed

+26
-6
lines changed

2 files changed

+26
-6
lines changed

src/utils/usage.ts

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,14 @@ interface UsageEventSchema extends Omit<UsageEvent, "action"> {
5454
action: UsageEventTxActionEnum;
5555
}
5656

57+
const URLS_LIST_TO_NOT_REPORT_USAGE = new Set([
58+
"/",
59+
"/favicon.ico",
60+
"/",
61+
"/system/health",
62+
"/json",
63+
]);
64+
5765
const createHeaderForRequest = (input: CreateHeaderForRequestParams) => {
5866
return {
5967
"Content-Type": "application/json",
@@ -71,6 +79,10 @@ export const withServerUsageReporting = (server: FastifyInstance) => {
7179
return;
7280
}
7381

82+
if (URLS_LIST_TO_NOT_REPORT_USAGE.has(reply.request.routerPath)) {
83+
return;
84+
}
85+
7486
const derivedClientId = deriveClientId(env.THIRDWEB_API_SECRET_KEY);
7587
const headers = createHeaderForRequest({
7688
clientId: derivedClientId,
@@ -84,10 +96,6 @@ export const withServerUsageReporting = (server: FastifyInstance) => {
8496
? await getChainIdFromChain(requestParams.chain)
8597
: "";
8698

87-
if (reply.request.routerPath === "" || !reply.request.routerPath) {
88-
return;
89-
}
90-
9199
const requestBody: UsageEventSchema = {
92100
source: "engine",
93101
action: UsageEventTxActionEnum.APIRequest,

src/worker/listeners/minedTxListener.ts

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
import cron from "node-cron";
22
import { getConfig } from "../../utils/cache/getConfig";
3+
import { logger } from "../../utils/logger";
34
import { updateMinedTx } from "../tasks/updateMinedTx";
45
import { updateMinedUserOps } from "../tasks/updateMinedUserOps";
56

67
let task: cron.ScheduledTask;
8+
let minedTxStarted = false;
79
export const minedTxListener = async () => {
810
const config = await getConfig();
911

@@ -16,7 +18,17 @@ export const minedTxListener = async () => {
1618
}
1719

1820
task = cron.schedule(config.minedTxListenerCronSchedule, async () => {
19-
await updateMinedTx();
20-
await updateMinedUserOps();
21+
if (!minedTxStarted) {
22+
minedTxStarted = true;
23+
await updateMinedTx();
24+
await updateMinedUserOps();
25+
minedTxStarted = false;
26+
} else {
27+
logger({
28+
service: "worker",
29+
level: "warn",
30+
message: "Mined tx listener already running, skipping",
31+
});
32+
}
2133
});
2234
};

0 commit comments

Comments
 (0)