米家调度独立模块注册, 避免被容器中无法加载的旧 cron.js 连带失效
Docker Build and Push / build-image (push) Successful in 4m36s
Docker Build and Push / build-image (push) Successful in 4m36s
This commit is contained in:
@@ -5,7 +5,6 @@ import { fetchNewsList, persistNews } from '../scripts/fetchers/news.fetcher.js'
|
||||
import { checkAfterRefresh } from './alert-engine.js'
|
||||
import { insertCronAlert } from '../scripts/lib/cron-alert.js'
|
||||
import { ApizeroError, oil, history } from './apizero/index.js'
|
||||
import * as mihome from './mihome/index.js'
|
||||
|
||||
function parseUrl(url) {
|
||||
const u = new URL(url)
|
||||
@@ -78,38 +77,3 @@ function scheduleOilHistory() {
|
||||
|
||||
scheduleNews()
|
||||
scheduleOilHistory()
|
||||
|
||||
// 环境监控: 每小时 5 分小时采样 + 每日 03:05 聚合/电量/vendor 历史补齐 (Asia/Shanghai)
|
||||
// 整点 +5min 缓冲, 避开米家高峰
|
||||
function scheduleMihome() {
|
||||
cron.schedule('5 * * * *', async () => {
|
||||
console.log('[cron] 米家小时采样触发 @ 上海 xx:05')
|
||||
try {
|
||||
const r = await mihome.syncNow()
|
||||
console.log('[cron] 米家采样完成: 家庭=' + r.homes + ' 设备=' + r.devices + ' 采样=' + r.sampled + ' 聚合=' + r.aggregated + ' (' + r.ms + 'ms)')
|
||||
} catch (e) {
|
||||
console.error('[cron] 米家小时采样失败:', e.message)
|
||||
}
|
||||
}, { timezone: 'Asia/Shanghai' })
|
||||
console.log('[cron] 已注册: 每小时 xx:05 米家温湿度采样')
|
||||
|
||||
cron.schedule('5 0,3 * * *', async () => {
|
||||
console.log('[cron] 米家每日维护触发 (00:05 / 03:05)')
|
||||
try {
|
||||
const r = await mihome.dailyMaintenance()
|
||||
console.log('[cron] 米家聚合完成: 采样=' + r.sampled + ' 聚合=' + r.aggregated
|
||||
+ ' vendor小时=' + r.vendorHours + ' vendor天=' + r.vendorDays + ' 缺口聚合=' + r.gapAggregated)
|
||||
} catch (e) {
|
||||
console.error('[cron] 米家每日维护失败:', e.message)
|
||||
}
|
||||
}, { timezone: 'Asia/Shanghai' })
|
||||
console.log('[cron] 已注册: 每天 00:05/03:05 米家日聚合 + vendor 补齐')
|
||||
|
||||
// 启动追赶: 服务重启/停机恢复后立即补一次 (不打断 5 分钟内的整点采样)
|
||||
setTimeout(() => {
|
||||
mihome.dailyMaintenance().catch((e) => console.error('[cron] 米家启动追赶失败:', e.message))
|
||||
}, 8000)
|
||||
console.log('[cron] 已注册: 启动后 8s 执行米家追赶同步')
|
||||
}
|
||||
|
||||
scheduleMihome()
|
||||
|
||||
Reference in New Issue
Block a user