email: real-time IMAP IDLE watchers (push on new mail); cron kept as backstop

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
2026-07-23 17:22:46 +00:00
co-authored by Claude Opus 4.8
parent 2bef99866f
commit 5a0b9ce70f
3 changed files with 174 additions and 1 deletions
+4
View File
@@ -1,6 +1,7 @@
import type { SidecarEvent } from '../protocol';
import type { Job, EnqueueParams } from '../../queue/types';
import { initEmailCron, stopEmailCron } from './email-cron';
import { initEmailIdle, stopEmailIdle } from './email-idle';
import { createSidecarConnector } from '../connect';
const API_URL = process.env.API_URL ?? `ws://127.0.0.1:${process.env.PORT ?? '5000'}`;
@@ -84,6 +85,8 @@ const connection = createSidecarConnector({
onConnected() {
// Start email cron once connected (so queue commands can reach API server)
initEmailCron();
// Real-time push via IMAP IDLE; the cron above is the slow backstop.
initEmailIdle();
},
});
@@ -91,6 +94,7 @@ const connection = createSidecarConnector({
function shutdown(signal: string) {
console.log(`[email] ${signal} received, shutting down...`);
stopEmailIdle();
stopEmailCron();
connection.destroy();
process.exit(0);