File tree 3 files changed +13
-6
lines changed
3 files changed +13
-6
lines changed Original file line number Diff line number Diff line change @@ -2,15 +2,15 @@ import {
2
2
QueueManager ,
3
3
type RequestingWithdrawal ,
4
4
WithdrawalGroupStatus ,
5
+ WithdrawalManager ,
5
6
WithdrawalPrisma ,
6
7
WithdrawalStatus ,
7
8
logger ,
8
- withdrawalManager ,
9
9
withdrawalPrisma ,
10
10
} from "@intmax2-withdrawal-aggregator/shared" ;
11
11
12
12
export const fetchRequestingWithdrawals = async ( ) => {
13
- const processedUUIDs = await withdrawalManager . getAllProcessedUUIDs ( ) ;
13
+ const processedUUIDs = await WithdrawalManager . getInstance ( ) . getAllProcessedUUIDs ( ) ;
14
14
15
15
const requestingWithdrawals = await withdrawalPrisma . withdrawal . findMany ( {
16
16
select : {
@@ -35,7 +35,7 @@ export const createWithdrawalGroup = async (group: RequestingWithdrawal[]) => {
35
35
const queueManager = QueueManager . getInstance ( "withdrawal-aggregator" ) ;
36
36
const now = new Date ( ) ;
37
37
38
- const groupId = await withdrawalManager . addGroup ( {
38
+ const groupId = await WithdrawalManager . getInstance ( ) . addGroup ( {
39
39
requestingWithdrawals : group . map ( ( withdrawal ) => ( {
40
40
uuid : withdrawal . uuid ,
41
41
} ) ) ,
Original file line number Diff line number Diff line change 4
4
WithdrawalStatus ,
5
5
logger ,
6
6
timeOperation ,
7
- withdrawalManager ,
7
+ WithdrawalManager ,
8
8
withdrawalPrisma ,
9
9
} from "@intmax2-withdrawal-aggregator/shared" ;
10
10
import { EXECUTION_REVERTED_ERROR_MESSAGE } from "../constants" ;
@@ -15,6 +15,7 @@ export const processQueueJob = async (jobData: QueueJobData) => {
15
15
} ;
16
16
17
17
const performJob = async ( data : QueueJobData ) : Promise < void > => {
18
+ const withdrawalManager = WithdrawalManager . getInstance ( ) ;
18
19
const { groupId } = data . payload ;
19
20
20
21
try {
Original file line number Diff line number Diff line change @@ -3,6 +3,7 @@ import type { WithdrawalGroup } from "../types";
3
3
import { RedisClient } from "./redis" ;
4
4
5
5
export class WithdrawalManager {
6
+ private static instance : WithdrawalManager ;
6
7
private redis : Redis ;
7
8
private readonly keyPrefix = "withdrawal:" ;
8
9
private readonly groupSetKey = "withdrawal:groups" ;
@@ -12,6 +13,13 @@ export class WithdrawalManager {
12
13
this . redis = RedisClient . getInstance ( ) . getClient ( ) ! ;
13
14
}
14
15
16
+ public static getInstance ( ) : WithdrawalManager {
17
+ if ( ! WithdrawalManager . instance ) {
18
+ WithdrawalManager . instance = new WithdrawalManager ( ) ;
19
+ }
20
+ return WithdrawalManager . instance ;
21
+ }
22
+
15
23
private getKey ( id : string ) : string {
16
24
return `${ this . keyPrefix } ${ id } ` ;
17
25
}
@@ -76,5 +84,3 @@ export class WithdrawalManager {
76
84
return groups . flatMap ( ( group ) => group . requestingWithdrawals . map ( ( { uuid } ) => uuid ) ) ;
77
85
}
78
86
}
79
-
80
- export const withdrawalManager = new WithdrawalManager ( ) ;
You can’t perform that action at this time.
0 commit comments