Files
openclaw/src/hooks/gmail-watcher-lifecycle.ts
T
samzong 2fa853dce5 fix(gateway): isolate gmail watcher restart and abort handling (#82395)
Merged via squash.

Prepared head SHA: 61502846df
Co-authored-by: samzong <13782141+samzong@users.noreply.github.com>
Co-authored-by: frankekn <4488090+frankekn@users.noreply.github.com>
Reviewed-by: @frankekn
2026-05-16 15:31:51 +08:00

43 lines
1.2 KiB
TypeScript

import type { OpenClawConfig } from "../config/types.openclaw.js";
import { isTruthyEnvValue } from "../infra/env.js";
import { startGmailWatcher } from "./gmail-watcher.js";
export type GMailWatcherLog = {
info: (msg: string) => void;
warn: (msg: string) => void;
error: (msg: string) => void;
};
export async function startGmailWatcherWithLogs(params: {
cfg: OpenClawConfig;
log: GMailWatcherLog;
onSkipped?: () => void;
isCancelled?: () => boolean;
signal?: AbortSignal;
}) {
if (isTruthyEnvValue(process.env.OPENCLAW_SKIP_GMAIL_WATCHER)) {
params.onSkipped?.();
return;
}
try {
const gmailResult = await startGmailWatcher(params.cfg, {
isCancelled: params.isCancelled,
signal: params.signal,
});
if (gmailResult.started) {
params.log.info("gmail watcher started");
return;
}
if (
gmailResult.reason &&
gmailResult.reason !== "hooks not enabled" &&
gmailResult.reason !== "no gmail account configured"
) {
params.log.warn(`gmail watcher not started: ${gmailResult.reason}`);
}
} catch (err) {
params.log.error(`gmail watcher failed to start: ${String(err)}`);
}
}