优化监控任务多账号配置

This commit is contained in:
yml
2026-05-25 17:44:42 +08:00
parent 30728c40be
commit d58d483944
17 changed files with 1062 additions and 182 deletions
@@ -34,7 +34,7 @@ function loadScheduledJobsConfigFromFile() {
)
}
function normalizeScheduledJobsConfig(rawValue: unknown) {
export function normalizeScheduledJobsConfig(rawValue: unknown) {
const source = isPlainObject(rawValue) ? rawValue : {}
const rawJobs = Array.isArray(source.jobs) ? source.jobs : []
const jobs = rawJobs.map((item) => normalizeScheduledJob(item)).filter(Boolean)
@@ -65,6 +65,7 @@ function normalizeScheduledJob(rawValue: unknown) {
function normalizeCloudtentaclesHealthJob(rawValue: JsonObject) {
const config = isPlainObject(rawValue.config) ? rawValue.config : {}
const defaultAssetThreshold = normalizeRangeInteger(config.assetThreshold, 500, 0, 999999)
return {
id: CLOUDTENTACLES_HEALTH_JOB_ID,
@@ -73,11 +74,57 @@ function normalizeCloudtentaclesHealthJob(rawValue: JsonObject) {
intervalSeconds: normalizeRangeInteger(rawValue.intervalSeconds, 300, 60, 86400),
cooldownSeconds: normalizeRangeInteger(rawValue.cooldownSeconds, 1800, 60, 86400),
config: {
assetThreshold: normalizeRangeInteger(config.assetThreshold, 500, 0, 999999),
assetThreshold: defaultAssetThreshold,
accounts: normalizeCloudtentaclesHealthAccounts(config, defaultAssetThreshold),
},
}
}
function normalizeCloudtentaclesHealthAccounts(config: JsonObject, defaultAssetThreshold: number) {
const rawAccounts = Array.isArray(config.accounts)
? config.accounts
: Array.isArray(config.sourceKeys)
? config.sourceKeys.map((sourceKey) => ({ sourceKey }))
: []
const accounts = rawAccounts
.map((item) => normalizeCloudtentaclesHealthAccount(item, defaultAssetThreshold))
.filter(Boolean) as ReturnType<typeof normalizeCloudtentaclesHealthAccount>[]
if (accounts.length === 0) {
accounts.push(normalizeCloudtentaclesHealthAccount({
sourceKey: config.sourceKey || 'default',
assetThreshold: defaultAssetThreshold,
}, defaultAssetThreshold))
}
const seen = new Set<string>()
return accounts.filter((item) => {
const sourceKey = String(item?.sourceKey || '').trim()
if (!sourceKey || seen.has(sourceKey)) {
return false
}
seen.add(sourceKey)
return true
})
}
function normalizeCloudtentaclesHealthAccount(rawValue: unknown, defaultAssetThreshold: number) {
const source = isPlainObject(rawValue) ? rawValue : {}
const sourceKey = String(source.sourceKey || source.key || '').trim() || 'default'
return {
sourceKey,
label: String(source.label || '').trim(),
enabled: source.enabled !== false,
assetThreshold: normalizeRangeInteger(
source.assetThreshold ?? source.threshold,
defaultAssetThreshold,
0,
999999,
),
}
}
function createDefaultScheduledJobsConfig() {
return {
enabled: true,
@@ -96,6 +143,14 @@ function createDefaultCloudtentaclesHealthJob() {
cooldownSeconds: 1800,
config: {
assetThreshold: 500,
accounts: [
{
sourceKey: 'default',
label: '默认账号',
enabled: true,
assetThreshold: 500,
},
],
},
}
}