Skip to content

Commit 25229e6

Browse files
authored
updated the API to send queued webhook as soon as data is added to DB & not on processing start (#451)
1 parent 88719b6 commit 25229e6

File tree

2 files changed

+29
-24
lines changed

2 files changed

+29
-24
lines changed

src/db/transactions/queueTxRaw.ts

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
import type { Prisma } from "@prisma/client";
22
import { PrismaTransaction } from "../../schema/prisma";
3+
import { TransactionStatusEnum } from "../../server/schemas/transaction";
34
import { simulateTx } from "../../server/utils/simulateTx";
5+
import { reportUsage, UsageEventTxActionEnum } from "../../utils/usage";
6+
import { sendWebhooks } from "../../utils/webhook";
47
import { getPrismaWithPostgresTx } from "../client";
58
import { getWalletDetails } from "../wallets/getWalletDetails";
69

@@ -45,7 +48,7 @@ export const queueTxRaw = async ({
4548
await simulateTx({ txRaw: tx });
4649
}
4750

48-
return prisma.transactions.create({
51+
const insertedData = await prisma.transactions.create({
4952
data: {
5053
...tx,
5154
fromAddress: tx.fromAddress?.toLowerCase(),
@@ -55,4 +58,29 @@ export const queueTxRaw = async ({
5558
accountAddress: tx.accountAddress?.toLowerCase(),
5659
},
5760
});
61+
62+
// Send queued webhook.
63+
sendWebhooks([
64+
{
65+
queueId: insertedData.id,
66+
status: TransactionStatusEnum.Queued,
67+
},
68+
]).catch((err) => {});
69+
70+
reportUsage([
71+
{
72+
input: {
73+
chainId: tx.chainId || undefined,
74+
fromAddress: tx.fromAddress || undefined,
75+
toAddress: tx.toAddress || undefined,
76+
value: tx.value || undefined,
77+
transactionHash: tx.transactionHash || undefined,
78+
functionName: tx.functionName || undefined,
79+
extension: tx.extension || undefined,
80+
},
81+
action: UsageEventTxActionEnum.QueueTx,
82+
},
83+
]);
84+
85+
return insertedData;
5886
};

src/worker/tasks/processTx.ts

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -61,29 +61,6 @@ export const processTx = async () => {
6161
message: `Received ${txs.length} transactions to process`,
6262
});
6363

64-
// Send queued webhook.
65-
await sendWebhooks(
66-
txs.map((tx) => ({
67-
queueId: tx.id,
68-
status: TransactionStatusEnum.Queued,
69-
})),
70-
);
71-
72-
reportUsage(
73-
txs.map((tx) => ({
74-
input: {
75-
chainId: tx.chainId || undefined,
76-
fromAddress: tx.fromAddress || undefined,
77-
toAddress: tx.toAddress || undefined,
78-
value: tx.value || undefined,
79-
transactionHash: tx.transactionHash || undefined,
80-
functionName: tx.functionName || undefined,
81-
extension: tx.extension || undefined,
82-
},
83-
action: UsageEventTxActionEnum.QueueTx,
84-
})),
85-
);
86-
8764
// 2. Update and sort transactions and user operations.
8865
const txsToSend: Transactions[] = [];
8966
const userOpsToSend: Transactions[] = [];

0 commit comments

Comments
 (0)