Skip to content

Commit 6f9b809

Browse files
authored
Add queue status system endpoint (#351)
* Add queue status system endpoint * Update
1 parent 6a92699 commit 6f9b809

File tree

4 files changed

+84
-3
lines changed

4 files changed

+84
-3
lines changed

src/db/transactions/getQueueStatus.ts

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import { prisma } from "../client";
2+
3+
interface GetQueueStatusParams {
4+
walletAddress?: string;
5+
}
6+
7+
export const getQueueStatus = async ({
8+
walletAddress,
9+
}: GetQueueStatusParams) => {
10+
const queued = await prisma.transactions.count({
11+
where: {
12+
fromAddress: walletAddress?.toLowerCase(),
13+
processedAt: null,
14+
errorMessage: null,
15+
},
16+
});
17+
18+
const pending = await prisma.transactions.count({
19+
where: {
20+
fromAddress: walletAddress?.toLowerCase(),
21+
sentAt: {
22+
not: null,
23+
},
24+
minedAt: null,
25+
errorMessage: null,
26+
},
27+
});
28+
29+
return {
30+
queued,
31+
pending,
32+
};
33+
};

src/server/routes/index.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,9 +96,10 @@ import { revokeRelayer } from "./relayer/revoke";
9696
import { getAllTransactions } from "./backend-wallet/getTransactions";
9797
import { sendTransactionBatch } from "./backend-wallet/sendTransactionBatch";
9898
import { withdraw } from "./backend-wallet/withdraw";
99-
import { healthCheck } from "./health";
10099
import { home } from "./home";
101100
import { updateRelayer } from "./relayer/update";
101+
import { healthCheck } from "./system/health";
102+
import { queueStatus } from "./system/queue";
102103
import { checkGroupStatus } from "./transaction/group";
103104
import { sendSignedTransaction } from "./transaction/sendSignedTx";
104105
import { sendSignedUserOp } from "./transaction/sendSignedUserOp";
@@ -208,4 +209,5 @@ export const withRoutes = async (fastify: FastifyInstance) => {
208209
// System
209210
await fastify.register(home);
210211
await fastify.register(healthCheck);
212+
await fastify.register(queueStatus);
211213
};

src/server/routes/health.ts renamed to src/server/routes/system/health.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { Static, Type } from "@sinclair/typebox";
22
import { FastifyInstance } from "fastify";
33
import { StatusCodes } from "http-status-codes";
4-
import { isDatabaseHealthy } from "../../db/client";
4+
import { isDatabaseHealthy } from "../../../db/client";
55

66
const ReplySchemaOk = Type.Object({
77
status: Type.String(),
@@ -19,7 +19,7 @@ export async function healthCheck(fastify: FastifyInstance) {
1919
Reply: Static<typeof ReplySchema>;
2020
}>({
2121
method: "GET",
22-
url: "/health",
22+
url: "/system/health",
2323
schema: {
2424
summary: "Check health",
2525
description: "Check the system health of Engine",

src/server/routes/system/queue.ts

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
import { Static, Type } from "@sinclair/typebox";
2+
import { FastifyInstance } from "fastify";
3+
import { StatusCodes } from "http-status-codes";
4+
import { getQueueStatus } from "../../../db/transactions/getQueueStatus";
5+
6+
const QuerySchema = Type.Object({
7+
walletAddress: Type.Optional(Type.String()),
8+
});
9+
10+
const ReplySchema = Type.Object({
11+
result: Type.Object({
12+
queued: Type.Number(),
13+
pending: Type.Number(),
14+
}),
15+
});
16+
17+
export async function queueStatus(fastify: FastifyInstance) {
18+
fastify.route<{
19+
Querystring: Static<typeof QuerySchema>;
20+
Reply: Static<typeof ReplySchema>;
21+
}>({
22+
method: "GET",
23+
url: "/system/queue",
24+
schema: {
25+
summary: "Check queue status",
26+
description: "Check the status of the queue",
27+
tags: ["System"],
28+
operationId: "queueStatus",
29+
querystring: QuerySchema,
30+
response: {
31+
[StatusCodes.OK]: ReplySchema,
32+
},
33+
},
34+
handler: async (req, res) => {
35+
const { walletAddress } = req.query;
36+
37+
const { queued, pending } = await getQueueStatus({ walletAddress });
38+
res.status(StatusCodes.OK).send({
39+
result: {
40+
queued,
41+
pending,
42+
},
43+
});
44+
},
45+
});
46+
}

0 commit comments

Comments
 (0)