Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(mis-server): 修复设置租户默认阈值时会无视账户阈值 #1406

Merged
merged 1 commit into from
Aug 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading