Skip to content

Commit 42b92ae

Browse files
Merge pull request #9 from InternetMaximalism/refactor
withdrawal manager
2 parents b9fbe04 + 0b71e3d commit 42b92ae

File tree

3 files changed

+13
-6
lines changed

3 files changed

+13
-6
lines changed

packages/collector/src/service/withdrawal.service.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,15 @@ import {
22
QueueManager,
33
type RequestingWithdrawal,
44
WithdrawalGroupStatus,
5+
WithdrawalManager,
56
WithdrawalPrisma,
67
WithdrawalStatus,
78
logger,
8-
withdrawalManager,
99
withdrawalPrisma,
1010
} from "@intmax2-withdrawal-aggregator/shared";
1111

1212
export const fetchRequestingWithdrawals = async () => {
13-
const processedUUIDs = await withdrawalManager.getAllProcessedUUIDs();
13+
const processedUUIDs = await WithdrawalManager.getInstance().getAllProcessedUUIDs();
1414

1515
const requestingWithdrawals = await withdrawalPrisma.withdrawal.findMany({
1616
select: {
@@ -35,7 +35,7 @@ export const createWithdrawalGroup = async (group: RequestingWithdrawal[]) => {
3535
const queueManager = QueueManager.getInstance("withdrawal-aggregator");
3636
const now = new Date();
3737

38-
const groupId = await withdrawalManager.addGroup({
38+
const groupId = await WithdrawalManager.getInstance().addGroup({
3939
requestingWithdrawals: group.map((withdrawal) => ({
4040
uuid: withdrawal.uuid,
4141
})),

packages/processor/src/service/job.service.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import {
44
WithdrawalStatus,
55
logger,
66
timeOperation,
7-
withdrawalManager,
7+
WithdrawalManager,
88
withdrawalPrisma,
99
} from "@intmax2-withdrawal-aggregator/shared";
1010
import { EXECUTION_REVERTED_ERROR_MESSAGE } from "../constants";
@@ -15,6 +15,7 @@ export const processQueueJob = async (jobData: QueueJobData) => {
1515
};
1616

1717
const performJob = async (data: QueueJobData): Promise<void> => {
18+
const withdrawalManager = WithdrawalManager.getInstance();
1819
const { groupId } = data.payload;
1920

2021
try {

packages/shared/src/lib/withdrawalManager.ts

+8-2
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import type { WithdrawalGroup } from "../types";
33
import { RedisClient } from "./redis";
44

55
export class WithdrawalManager {
6+
private static instance: WithdrawalManager;
67
private redis: Redis;
78
private readonly keyPrefix = "withdrawal:";
89
private readonly groupSetKey = "withdrawal:groups";
@@ -12,6 +13,13 @@ export class WithdrawalManager {
1213
this.redis = RedisClient.getInstance().getClient()!;
1314
}
1415

16+
public static getInstance(): WithdrawalManager {
17+
if (!WithdrawalManager.instance) {
18+
WithdrawalManager.instance = new WithdrawalManager();
19+
}
20+
return WithdrawalManager.instance;
21+
}
22+
1523
private getKey(id: string): string {
1624
return `${this.keyPrefix}${id}`;
1725
}
@@ -76,5 +84,3 @@ export class WithdrawalManager {
7684
return groups.flatMap((group) => group.requestingWithdrawals.map(({ uuid }) => uuid));
7785
}
7886
}
79-
80-
export const withdrawalManager = new WithdrawalManager();

0 commit comments

Comments
 (0)