Skip to content

Commit

Permalink
fix(mis-server): 修复设置租户默认阈值时会无视账户阈值 (#1406)
Browse files Browse the repository at this point in the history
## 做了什么
### 1.  在修改租户的封锁阈值时,之前会把所有账户都处理了,但是对于单独设置了账户阈值的账户来说,并不需要走这套逻辑
### 2. 增加设置租户默认阈值时的封锁和解封账户日志
  • Loading branch information
OYX-1 authored Aug 20, 2024
1 parent 2519bc7 commit 9300087
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 3 deletions.
5 changes: 5 additions & 0 deletions .changeset/spicy-lies-count.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@scow/mis-server": patch
---

修复设置租户默认阈值时会无视账户阈值的问题,并增加封锁和解封账户的日志
34 changes: 31 additions & 3 deletions apps/mis-server/src/services/tenant.ts
Original file line number Diff line number Diff line change
Expand Up @@ -183,10 +183,15 @@ export const tenantServiceServer = plugin((server) => {
tenant.defaultAccountBlockThreshold = new Decimal(moneyToNumber(blockThresholdAmount));

// 判断租户下各账户是否使用该租户封锁阈值,使用后是否需要在集群中进行封锁
const accounts = await em.find(Account, { tenant: tenant, blockThresholdAmount : {} }, {
const accounts = await em.find(Account, { tenant: tenant, blockThresholdAmount : undefined }, {
populate: ["tenant"],
});

const blockedAccounts: string[] = [];
const blockedFailedAccounts: string[] = [];
const unBlockedAccounts: string[] = [];
const unBlockedFailedAccounts: string[] = [];

const currentActivatedClusters = await getActivatedClusters(em, logger);
if (accounts.length > 0) {
await Promise.allSettled(accounts
Expand All @@ -202,20 +207,43 @@ export const tenantServiceServer = plugin((server) => {
if (shouldBlockInCluster) {
logger.info("Account %s may be out of balance when using default tenant block threshold amount. "
+ "Block the account.", account.accountName);
await blockAccount(account, currentActivatedClusters, server.ext.clusters, logger);

try {
await blockAccount(account, currentActivatedClusters, server.ext.clusters, logger);
blockedAccounts.push(account.accountName);
} catch (error) {
logger.warn("Failed to block account %s in slurm: %o", account.accountName, error);
blockedFailedAccounts.push(account.accountName);
}

}

if (!shouldBlockInCluster) {
logger.info("The balance of Account %s is greater than the default tenant block threshold amount. "
+ "Unblock the account.", account.accountName);
await unblockAccount(account, currentActivatedClusters, server.ext.clusters, logger);

try {
await unblockAccount(account, currentActivatedClusters, server.ext.clusters, logger);
unBlockedAccounts.push(account.accountName);
} catch (error) {
logger.warn("Failed to unBlock account %s in slurm: %o", account.accountName, error);
unBlockedFailedAccounts.push(account.accountName);
}

}
}),
).catch((e) => {
logger.error("Block or unblock account failed when set a new default tenant threshold amount.", e);
});
}


logger.info("Updated block status in slurm of the following accounts: %o", blockedAccounts);
logger.info("Updated block status failed in slurm of the following accounts: %o", blockedFailedAccounts);

logger.info("Updated unBlock status in slurm of the following accounts: %o", unBlockedAccounts);
logger.info("Updated unBlock status failed in slurm of the following accounts: %o", unBlockedFailedAccounts);

if (accounts.length > 0) {
await em.persistAndFlush([...accounts, tenant]);
} else {
Expand Down

0 comments on commit 9300087

Please sign in to comment.