refactor(gateway): share gmail watcher startup flow

This commit is contained in:
Peter Steinberger
2026-02-18 17:41:13 +00:00
parent e702a9eb52
commit 6187e2afbd
4 changed files with 144 additions and 36 deletions

View File

@@ -3,7 +3,8 @@ import { getTotalPendingReplies } from "../auto-reply/reply/dispatcher-registry.
import type { CliDeps } from "../cli/deps.js";
import { resolveAgentMaxConcurrent, resolveSubagentMaxConcurrent } from "../config/agent-limits.js";
import type { loadConfig } from "../config/config.js";
import { startGmailWatcher, stopGmailWatcher } from "../hooks/gmail-watcher.js";
import { startGmailWatcherWithLogs } from "../hooks/gmail-watcher-lifecycle.js";
import { stopGmailWatcher } from "../hooks/gmail-watcher.js";
import { isTruthyEnvValue } from "../infra/env.js";
import type { HeartbeatRunner } from "../infra/heartbeat-runner.js";
import { resetDirectoryCache } from "../infra/outbound/target-resolver.js";
@@ -90,24 +91,12 @@ export function createGatewayReloadHandlers(params: {
if (plan.restartGmailWatcher) {
await stopGmailWatcher().catch(() => {});
if (!isTruthyEnvValue(process.env.OPENCLAW_SKIP_GMAIL_WATCHER)) {
try {
const gmailResult = await startGmailWatcher(nextConfig);
if (gmailResult.started) {
params.logHooks.info("gmail watcher started");
} else if (
gmailResult.reason &&
gmailResult.reason !== "hooks not enabled" &&
gmailResult.reason !== "no gmail account configured"
) {
params.logHooks.warn(`gmail watcher not started: ${gmailResult.reason}`);
}
} catch (err) {
params.logHooks.error(`gmail watcher failed to start: ${String(err)}`);
}
} else {
params.logHooks.info("skipping gmail watcher restart (OPENCLAW_SKIP_GMAIL_WATCHER=1)");
}
await startGmailWatcherWithLogs({
cfg: nextConfig,
log: params.logHooks,
onSkipped: () =>
params.logHooks.info("skipping gmail watcher restart (OPENCLAW_SKIP_GMAIL_WATCHER=1)"),
});
}
if (plan.restartChannels.size > 0) {