import { type SyncMailboxesEvent } from "@remit/backend/trigger-sync"; import type { AccountItem, FifoQueueProducer, IAccountRepository } from "@remit/data-ports"; import type { Logger } from "@remit/logger"; export interface CalendarSubscriptionTally { refreshed: number; failed: number; notDue: number; } export interface RunSchedulerTickDeps { accountService: Pick; queue: FifoQueueProducer; log: Logger; offlineIntervalMs: number; /** * How often this tick itself runs — the dedup-id bucket width for * `buildScheduledSyncDedupId`, so consecutive ticks each get a fresh id. */ tickIntervalMs: number; /** Injectable for tests; defaults to `Date.now()`. */ now?: number; /** * Collect attachment bytes the database does not know about, for one account. * * The tick already walks every account on a cadence, which is the only thing * this needs. It exists because an upload URL minted for a draft stays valid * after that draft is discarded, and where the browser writes straight to * block storage nothing is in the path to refuse it — see * `sweepAbandonedOutboxAttachments`. Optional only so a test can leave it out; * both real entry points pass it. */ sweepAttachments?: (account: AccountItem) => Promise; /** * Re-read the calendar subscriptions whose last fetch is older than * `offlineIntervalMs` — the same knob that says how stale mail may get. * Optional only so a test can leave it out; both real entry points pass it. */ refreshCalendarSubscriptions?: (now: number, intervalMs: number) => Promise; redriveStrandedPlacements: (account: AccountItem, now: number) => Promise; } export interface SchedulerTickResult { scanned: number; enqueued: number; skipped: number; swept: number; sweepFailed: number; subscriptionsRefreshed: number; subscriptionsFailed: number; redriven: number; redriveFailed: number; } /** * One tick of the periodic mailbox-sync scheduler (#1247, restructured * #1251). Pages through every account (never loading the whole account base * into memory), decides per account via `isStale` against the single * offline threshold, and enqueues SYNC_MAILBOXES for the accounts that are * due — in bounded-concurrency batches, never an unbounded `Promise.all`. * * Every enqueue goes through the same `triggerAccountSync` the manual * POST /sync path uses, with a scheduler-specific, time-bucketed dedup id * (`buildScheduledSyncDedupId`, bucketed by `tickIntervalMs`) so this tick * can never collide with its own previous tick or with a concurrent manual * trigger (see trigger-sync.ts). Concurrent-sync safety for the mailbox * itself is MailboxLockService's job, inside the worker handler — this tick * only decides "is a sync due" and enqueues; it never talks to IMAP. */ export declare const runSchedulerTick: (deps: RunSchedulerTickDeps) => Promise;