refactor: manage monitor via gateway hooks
This commit is contained in:
@@ -12,8 +12,10 @@
|
||||
* local monitor_port communication path.
|
||||
*/
|
||||
import { hostname, freemem, totalmem, uptime, loadavg, platform } from 'os';
|
||||
import { getLivePluginConfig, type HarborForgeMonitorConfig } from './core/live-config';
|
||||
import { getPluginConfig } from './core/config';
|
||||
import { MonitorBridgeClient, type OpenClawMeta } from './core/monitor-bridge';
|
||||
import { registerGatewayStartHook } from './hooks/gateway-start';
|
||||
import { registerGatewayStopHook } from './hooks/gateway-stop';
|
||||
import {
|
||||
createCalendarBridgeClient,
|
||||
createCalendarScheduler,
|
||||
@@ -55,18 +57,8 @@ export default {
|
||||
warn: (...args: any[]) => console.warn('[HarborForge]', ...args),
|
||||
};
|
||||
|
||||
const baseConfig: HarborForgeMonitorConfig = {
|
||||
enabled: true,
|
||||
backendUrl: 'https://monitor.hangman-lab.top',
|
||||
identifier: '',
|
||||
reportIntervalSec: 30,
|
||||
httpFallbackIntervalSec: 60,
|
||||
logLevel: 'info',
|
||||
...(api.pluginConfig || {}),
|
||||
};
|
||||
|
||||
function resolveConfig() {
|
||||
return getLivePluginConfig(api, baseConfig);
|
||||
return getPluginConfig(api);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -304,38 +296,24 @@ export default {
|
||||
}
|
||||
}
|
||||
|
||||
api.on('gateway_start', () => {
|
||||
logger.info('HarborForge plugin active');
|
||||
|
||||
// Push metadata to Monitor bridge on startup and periodically.
|
||||
// Interval aligns with typical Monitor heartbeat cycle (30s).
|
||||
// If Monitor bridge is unreachable, pushes silently fail.
|
||||
const live = resolveConfig();
|
||||
const intervalSec = live.reportIntervalSec || 30;
|
||||
|
||||
// Initial push (delayed 2s to let Monitor bridge start)
|
||||
setTimeout(() => pushMetaToMonitor(), 2000);
|
||||
|
||||
metaPushInterval = setInterval(
|
||||
() => pushMetaToMonitor(),
|
||||
intervalSec * 1000,
|
||||
);
|
||||
|
||||
// Start calendar scheduler (delayed to let everything initialize)
|
||||
if (live.enabled !== false) {
|
||||
setTimeout(() => startCalendarScheduler(), 5000);
|
||||
}
|
||||
registerGatewayStartHook(api, {
|
||||
logger,
|
||||
pushMetaToMonitor,
|
||||
startCalendarScheduler,
|
||||
setMetaPushInterval(handle) {
|
||||
metaPushInterval = handle;
|
||||
},
|
||||
});
|
||||
|
||||
api.on('gateway_stop', () => {
|
||||
logger.info('HarborForge plugin stopping');
|
||||
|
||||
if (metaPushInterval) {
|
||||
clearInterval(metaPushInterval);
|
||||
registerGatewayStopHook(api, {
|
||||
logger,
|
||||
getMetaPushInterval() {
|
||||
return metaPushInterval;
|
||||
},
|
||||
clearMetaPushInterval() {
|
||||
metaPushInterval = null;
|
||||
}
|
||||
|
||||
stopCalendarScheduler();
|
||||
},
|
||||
stopCalendarScheduler,
|
||||
});
|
||||
|
||||
// Tool: plugin status
|
||||
|
||||
Reference in New Issue
Block a user