Use the same mechanism as dreaming/memory-core: acquire cron service from gateway_start event, create one-shot cron job with wakeMode: "now" and deleteAfterRun: true. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
48 lines
1.8 KiB
TypeScript
48 lines
1.8 KiB
TypeScript
import { hostname } from 'os';
|
|
import { getPluginConfig } from '../core/config';
|
|
import { startManagedMonitor } from '../core/managed-monitor';
|
|
|
|
export function registerGatewayStartHook(api: any, deps: {
|
|
logger: any;
|
|
pushMetaToMonitor: () => Promise<void>;
|
|
startCalendarScheduler: () => void;
|
|
setMetaPushInterval: (handle: ReturnType<typeof setInterval>) => void;
|
|
onCronServiceAvailable?: (cron: any) => void;
|
|
}) {
|
|
const { logger, pushMetaToMonitor, startCalendarScheduler, setMetaPushInterval } = deps;
|
|
|
|
api.on('gateway_start', (event?: any) => {
|
|
// Extract cron service from gateway startup event (same as memory-core dreaming)
|
|
if (event && deps.onCronServiceAvailable) {
|
|
const context = event?.context;
|
|
const cron = context?.cron ?? context?.deps?.cron;
|
|
if (cron && typeof cron.add === 'function') {
|
|
deps.onCronServiceAvailable(cron);
|
|
logger.info('HarborForge: cron service acquired from gateway_start');
|
|
}
|
|
}
|
|
logger.info('HarborForge plugin active');
|
|
const live = getPluginConfig(api);
|
|
|
|
startManagedMonitor(logger, {
|
|
managedMonitor: live.managedMonitor,
|
|
backendUrl: live.backendUrl,
|
|
identifier: live.identifier,
|
|
apiKey: live.apiKey,
|
|
monitor_port: live.monitor_port,
|
|
reportIntervalSec: live.reportIntervalSec,
|
|
logLevel: live.logLevel,
|
|
});
|
|
|
|
const intervalSec = live.reportIntervalSec || 30;
|
|
setTimeout(() => void pushMetaToMonitor(), 2000);
|
|
setMetaPushInterval(setInterval(() => void pushMetaToMonitor(), intervalSec * 1000));
|
|
|
|
if (live.enabled !== false && live.calendarEnabled !== false) {
|
|
setTimeout(() => startCalendarScheduler(), 5000);
|
|
}
|
|
|
|
logger.info(`HarborForge startup config identifier=${live.identifier || hostname()} backend=${live.backendUrl}`);
|
|
});
|
|
}
|