简单的定时任务--ok
This commit is contained in:
@@ -6,10 +6,21 @@ import {
|
||||
saveNotificationConfig,
|
||||
} from '../../notification/config-service.js'
|
||||
import { sendInternalNotification } from '../../notification/notification-service.js'
|
||||
import {
|
||||
getScheduledJobsConfig,
|
||||
getScheduledJobsFilePath,
|
||||
saveScheduledJobsConfig,
|
||||
} from '../../scheduler/config-service.js'
|
||||
import {
|
||||
getScheduledJobRuntimeStates,
|
||||
reloadScheduledJobs,
|
||||
runScheduledJobNow,
|
||||
} from '../../scheduler/scheduler-service.js'
|
||||
import { maskSecret } from './mappers.js'
|
||||
|
||||
/** @typedef {import('../../../types/admin-write-inputs.js').AdminNotificationConfigInput} AdminNotificationConfigInput */
|
||||
/** @typedef {import('../../../types/admin-write-inputs.js').AdminNotificationTestInput} AdminNotificationTestInput */
|
||||
/** @typedef {import('../../../types/admin-write-inputs.js').AdminScheduledJobsConfigInput} AdminScheduledJobsConfigInput */
|
||||
|
||||
export function getAdminNotificationConfig() {
|
||||
const config = getNotificationConfig()
|
||||
@@ -40,6 +51,37 @@ export async function testAdminNotification(payload = /** @type {AdminNotificati
|
||||
})
|
||||
}
|
||||
|
||||
export function getAdminScheduledJobsConfig() {
|
||||
const config = getScheduledJobsConfig()
|
||||
|
||||
return {
|
||||
filePath: getScheduledJobsFilePath(),
|
||||
source: mapAdminScheduledJobsConfig(config),
|
||||
runtime: getScheduledJobRuntimeStates(),
|
||||
}
|
||||
}
|
||||
|
||||
/** @param {AdminScheduledJobsConfigInput} [payload] */
|
||||
export function updateAdminScheduledJobsConfig(payload = /** @type {AdminScheduledJobsConfigInput} */ ({})) {
|
||||
const saved = saveScheduledJobsConfig(payload)
|
||||
reloadScheduledJobs()
|
||||
|
||||
return {
|
||||
filePath: getScheduledJobsFilePath(),
|
||||
source: mapAdminScheduledJobsConfig(saved),
|
||||
runtime: getScheduledJobRuntimeStates(),
|
||||
}
|
||||
}
|
||||
|
||||
export async function runAdminScheduledJobNow(jobId) {
|
||||
const result = await runScheduledJobNow(jobId)
|
||||
|
||||
return {
|
||||
result,
|
||||
runtime: getScheduledJobRuntimeStates(),
|
||||
}
|
||||
}
|
||||
|
||||
function mapAdminNotificationConfig(config = {}) {
|
||||
const bark = config.channels?.bark || {}
|
||||
|
||||
@@ -60,3 +102,19 @@ function mapAdminNotificationConfig(config = {}) {
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
function mapAdminScheduledJobsConfig(config = {}) {
|
||||
return {
|
||||
enabled: config.enabled !== false,
|
||||
jobs: (Array.isArray(config.jobs) ? config.jobs : []).map((item) => ({
|
||||
id: String(item.id || '').trim(),
|
||||
type: String(item.type || '').trim(),
|
||||
enabled: item.enabled === true,
|
||||
intervalSeconds: Number(item.intervalSeconds || 300),
|
||||
cooldownSeconds: Number(item.cooldownSeconds || 1800),
|
||||
config: {
|
||||
assetThreshold: Number(item.config?.assetThreshold || 500),
|
||||
},
|
||||
})),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -54,4 +54,7 @@ export {
|
||||
getAdminNotificationConfig,
|
||||
updateAdminNotificationConfig,
|
||||
testAdminNotification,
|
||||
getAdminScheduledJobsConfig,
|
||||
updateAdminScheduledJobsConfig,
|
||||
runAdminScheduledJobNow,
|
||||
} from './notification-service.js'
|
||||
|
||||
Reference in New Issue
Block a user