@go-mailer/jarvis 10.9.4 → 10.9.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -92,14 +92,21 @@ const WalletThrottler = async ({
|
|
|
92
92
|
}
|
|
93
93
|
};
|
|
94
94
|
|
|
95
|
-
const loadCache = async ({ tenant_id, wallet_type, balance }) => {
|
|
95
|
+
const loadCache = async ({ tenant_id, wallet_type, balance, rate = 1 }) => {
|
|
96
96
|
const balance_key = `wallet:tenant:${tenant_id}:wallet:${wallet_type}`;
|
|
97
|
+
const rate_key = `wallet:tenant:${tenant_id}:wallet:${wallet_type}:rate`;
|
|
97
98
|
|
|
98
99
|
// Load balance from DB if missing
|
|
99
100
|
const redis_balance = await redisClient.get(balance_key);
|
|
100
101
|
if (redis_balance === null) {
|
|
101
102
|
await redisClient.set(balance_key, balance);
|
|
102
103
|
}
|
|
104
|
+
|
|
105
|
+
// Load rate from DB if missing
|
|
106
|
+
const redis_rate = await redisClient.get(rate_key);
|
|
107
|
+
if (redis_rate === null) {
|
|
108
|
+
await redisClient.set(rate_key, rate);
|
|
109
|
+
}
|
|
103
110
|
};
|
|
104
111
|
|
|
105
112
|
const refundCredits = async ({
|
|
@@ -139,11 +146,13 @@ const WalletThrottler = async ({
|
|
|
139
146
|
);
|
|
140
147
|
};
|
|
141
148
|
|
|
142
|
-
const topUpCredits = async ({ tenant_id, wallet_type, amount = 0 }) => {
|
|
149
|
+
const topUpCredits = async ({ tenant_id, wallet_type, amount = 0, rate = 1 }) => {
|
|
143
150
|
const balance_key = `wallet:tenant:${tenant_id}:wallet:${wallet_type}`;
|
|
144
|
-
|
|
151
|
+
const rate_key = `wallet:tenant:${tenant_id}:wallet:${wallet_type}:rate`;
|
|
145
152
|
// Increment Redis (instant across all instances)
|
|
146
153
|
await redisClient.incrBy(balance_key, amount);
|
|
154
|
+
|
|
155
|
+
await redisClient.set(rate_key, rate); // Update rate if provided
|
|
147
156
|
console.log(`Top-up ${amount} for ${tenant_id} on wallet ${wallet_type}`);
|
|
148
157
|
};
|
|
149
158
|
|