@remit/imap-worker 0.0.91 → 0.0.93

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -2,6 +2,9 @@ import { attemptBudget } from "@remit/sqs-client/attempt-budget";
2
2
  import { DEFAULT_MAILBOX_FRESHNESS_MS, defaultImapWorkerConfig, } from "./context.js";
3
3
  import { workerVersion } from "./worker-version.js";
4
4
  const DEFAULT_CONNECTIONS_PER_ACCOUNT = 2;
5
+ const BODY_BATCH_SIZE = 200;
6
+ const BODY_PROCESS_CONCURRENCY = 8;
7
+ const BODY_PROCESS_BYTES_IN_FLIGHT = 256 * 1024 * 1024;
5
8
  // Deployments that drive sync from a test harness set MAILBOX_FRESHNESS_MS low
6
9
  // so their explicit nudges are never no-oped by the freshness gate.
7
10
  export const resolveMailboxFreshnessMs = (env) => {
@@ -23,7 +26,9 @@ export const imapWorkerConfigFromEnv = (env) => {
23
26
  messageDelete: attemptBudget("MESSAGE_DELETE_MAX_ATTEMPTS", attempts.messageDelete, env),
24
27
  messageCopy: attemptBudget("MESSAGE_COPY_MAX_ATTEMPTS", attempts.messageCopy, env),
25
28
  },
26
- bodyBatchSize: defaultImapWorkerConfig.bodyBatchSize,
29
+ bodyBatchSize: BODY_BATCH_SIZE,
30
+ bodyProcessConcurrency: BODY_PROCESS_CONCURRENCY,
31
+ bodyProcessBytesInFlight: BODY_PROCESS_BYTES_IN_FLIGHT,
27
32
  mailboxFreshnessMs: resolveMailboxFreshnessMs(env),
28
33
  workerVersion: workerVersion(),
29
34
  };
package/dist/context.d.ts CHANGED
@@ -29,6 +29,8 @@ export interface AttemptBudgets {
29
29
  export interface ImapWorkerConfig {
30
30
  readonly attempts: AttemptBudgets;
31
31
  readonly bodyBatchSize: number;
32
+ readonly bodyProcessConcurrency: number;
33
+ readonly bodyProcessBytesInFlight: number;
32
34
  readonly mailboxFreshnessMs: number;
33
35
  readonly workerVersion: string;
34
36
  }
@@ -43,4 +45,4 @@ export interface ProcessContext {
43
45
  readonly accountObjects: AccountObjectStore;
44
46
  }
45
47
  export declare const DEFAULT_MAILBOX_FRESHNESS_MS = 60000;
46
- export declare const defaultImapWorkerConfig: Omit<ImapWorkerConfig, "workerVersion">;
48
+ export declare const defaultImapWorkerConfig: Omit<ImapWorkerConfig, "workerVersion" | "bodyBatchSize" | "bodyProcessConcurrency" | "bodyProcessBytesInFlight">;
package/dist/context.js CHANGED
@@ -10,6 +10,5 @@ export const defaultImapWorkerConfig = {
10
10
  messageDelete: 3,
11
11
  messageCopy: 3,
12
12
  },
13
- bodyBatchSize: 200,
14
13
  mailboxFreshnessMs: DEFAULT_MAILBOX_FRESHNESS_MS,
15
14
  };
@@ -132,7 +132,11 @@ export const syncMessageBody = async (event, ctx, receiveCount) => {
132
132
  placement: await resolveFolderPlacement(mailboxSpecialUseService, accountId, mailbox.mailboxId),
133
133
  };
134
134
  await (async () => {
135
- const result = await bodySyncService.syncBodies(messageIds, accountId, account.accountConfigId, folder, getConnectionChecked, force);
135
+ const result = await bodySyncService.syncBodies(messageIds, accountId, account.accountConfigId, folder, getConnectionChecked, {
136
+ force,
137
+ concurrency: config.bodyProcessConcurrency,
138
+ bytesInFlight: config.bodyProcessBytesInFlight,
139
+ });
136
140
  if (result.failedMessageIds.length === 0) {
137
141
  return;
138
142
  }
@@ -2,11 +2,7 @@ import type { RemitClient } from "@remit/backend/client";
2
2
  import { type CalendarFeedFetcher } from "@remit/calendar-service";
3
3
  import type { ICalendarCollectionRepository, ICalendarStore } from "@remit/data-ports";
4
4
  import type { Logger } from "@remit/logger";
5
- export interface CalendarSubscriptionTally {
6
- refreshed: number;
7
- failed: number;
8
- notDue: number;
9
- }
5
+ import type { CalendarSubscriptionTally } from "./run-tick.js";
10
6
  export interface CalendarSubscriptionRefreshDeps {
11
7
  calendarCollection: Pick<ICalendarCollectionRepository, "listEnabledSubscriptions">;
12
8
  calendarStore: ICalendarStore;
@@ -21,7 +21,9 @@
21
21
  * accounts, and the checker's stall threshold is derived from those values —
22
22
  * see deploy/vps/docker-compose.sqlite.yml's `scheduler` service.
23
23
  */
24
- export declare const getTickIntervalMs: (env?: NodeJS.ProcessEnv) => number;
25
- export declare const getOfflineIntervalMs: (env?: NodeJS.ProcessEnv) => number;
24
+ export declare const DEFAULT_TICK_INTERVAL_MS: number;
25
+ export declare const DEFAULT_OFFLINE_INTERVAL_MS: number;
26
+ export declare const getTickIntervalMs: (env: Readonly<Record<string, string | undefined>>) => number;
27
+ export declare const getOfflineIntervalMs: (env: Readonly<Record<string, string | undefined>>) => number;
26
28
  export declare const SCHEDULER_PAGE_SIZE = 100;
27
29
  export declare const SCHEDULER_ENQUEUE_CONCURRENCY = 10;
@@ -21,16 +21,16 @@
21
21
  * accounts, and the checker's stall threshold is derived from those values —
22
22
  * see deploy/vps/docker-compose.sqlite.yml's `scheduler` service.
23
23
  */
24
- const DEFAULT_TICK_INTERVAL_SECONDS = 60 * 60; // 1 hour
25
- const DEFAULT_OFFLINE_INTERVAL_SECONDS = 12 * 60 * 60; // 12 hours
26
- const parsePositiveIntSeconds = (raw, fallback) => {
24
+ export const DEFAULT_TICK_INTERVAL_MS = 60 * 60 * 1000;
25
+ export const DEFAULT_OFFLINE_INTERVAL_MS = 12 * 60 * 60 * 1000;
26
+ const parsePositiveSecondsAsMs = (raw, fallbackMs) => {
27
27
  if (!raw)
28
- return fallback;
28
+ return fallbackMs;
29
29
  const parsed = Number.parseInt(raw, 10);
30
- return Number.isFinite(parsed) && parsed > 0 ? parsed : fallback;
30
+ return Number.isFinite(parsed) && parsed > 0 ? parsed * 1000 : fallbackMs;
31
31
  };
32
- export const getTickIntervalMs = (env = process.env) => parsePositiveIntSeconds(env.MAILBOX_SYNC_TICK_INTERVAL_SECONDS, DEFAULT_TICK_INTERVAL_SECONDS) * 1000;
33
- export const getOfflineIntervalMs = (env = process.env) => parsePositiveIntSeconds(env.MAILBOX_SYNC_OFFLINE_INTERVAL_SECONDS, DEFAULT_OFFLINE_INTERVAL_SECONDS) * 1000;
32
+ export const getTickIntervalMs = (env) => parsePositiveSecondsAsMs(env.MAILBOX_SYNC_TICK_INTERVAL_SECONDS, DEFAULT_TICK_INTERVAL_MS);
33
+ export const getOfflineIntervalMs = (env) => parsePositiveSecondsAsMs(env.MAILBOX_SYNC_OFFLINE_INTERVAL_SECONDS, DEFAULT_OFFLINE_INTERVAL_MS);
34
34
  // Page size + enqueue concurrency are implementation details of the tick
35
35
  // itself, not stage config — unlike the two intervals above, nothing outside
36
36
  // this worker needs to agree with them.
@@ -3,11 +3,9 @@ import { createLogger } from "@remit/logger";
3
3
  import { installNodeLogger, withTelemetry } from "@remit/logger-lambda/node";
4
4
  import { lambdaEmitEvent } from "../lambda-context.js";
5
5
  import { sqsWorkerQueues, workerQueueUrlsFromEnv } from "../sqs-queues.js";
6
- import { buildAttachmentSweep } from "./attachment-sweep.js";
7
6
  import { buildCalendarSubscriptionRefresh } from "./calendar-subscriptions.js";
8
7
  import { getOfflineIntervalMs, getTickIntervalMs } from "./config.js";
9
- import { runSchedulerTick } from "./run-tick.js";
10
- import { redriveStrandedPlacements } from "./stranded-placement-redrive.js";
8
+ import { buildAttachmentSweep, redriveStrandedPlacements, runSchedulerTick, } from "./tick.js";
11
9
  installNodeLogger();
12
10
  const log = createLogger();
13
11
  /**
@@ -34,8 +32,8 @@ export const buildScheduledHandler = (queues) => withTelemetry(async (event) =>
34
32
  accountService: client.account,
35
33
  queue: queues.mailboxes,
36
34
  log,
37
- tickIntervalMs: getTickIntervalMs(),
38
- offlineIntervalMs: getOfflineIntervalMs(),
35
+ tickIntervalMs: getTickIntervalMs(process.env),
36
+ offlineIntervalMs: getOfflineIntervalMs(process.env),
39
37
  now,
40
38
  // The hosted side is the one that needs this: a browser PUTs straight
41
39
  // to block storage, so nothing refuses an upload against a draft that is
@@ -1,7 +1,11 @@
1
1
  import { type SyncMailboxesEvent } from "@remit/backend/trigger-sync";
2
2
  import type { AccountItem, FifoQueueProducer, IAccountRepository } from "@remit/data-ports";
3
3
  import type { Logger } from "@remit/logger";
4
- import type { CalendarSubscriptionTally } from "./calendar-subscriptions.js";
4
+ export interface CalendarSubscriptionTally {
5
+ refreshed: number;
6
+ failed: number;
7
+ notDue: number;
8
+ }
5
9
  export interface RunSchedulerTickDeps {
6
10
  accountService: Pick<IAccountRepository, "listAllAccountsPage">;
7
11
  queue: FifoQueueProducer<SyncMailboxesEvent>;
@@ -8,12 +8,10 @@ import { backfillSearchText } from "@remit/mailbox-service";
8
8
  import { clearHeartbeats, createHeartbeat } from "@remit/sqs-client/heartbeat";
9
9
  import { lambdaEmitEvent } from "../lambda-context.js";
10
10
  import { sqsWorkerQueues, workerQueueUrlsFromEnv } from "../sqs-queues.js";
11
- import { buildAttachmentSweep } from "./attachment-sweep.js";
12
11
  import { buildCalendarSubscriptionRefresh } from "./calendar-subscriptions.js";
13
12
  import { getOfflineIntervalMs, getTickIntervalMs } from "./config.js";
14
13
  import { runSchedulerLoop } from "./loop.js";
15
- import { runSchedulerTick } from "./run-tick.js";
16
- import { redriveStrandedPlacements } from "./stranded-placement-redrive.js";
14
+ import { buildAttachmentSweep, redriveStrandedPlacements, runSchedulerTick, } from "./tick.js";
17
15
  installNodeLogger();
18
16
  /**
19
17
  * The scheduled-sync runner for every deployment that has no EventBridge: the
@@ -36,8 +34,8 @@ installNodeLogger();
36
34
  */
37
35
  const log = createLogger();
38
36
  const queues = sqsWorkerQueues(workerQueueUrlsFromEnv());
39
- const tickIntervalMs = getTickIntervalMs();
40
- const offlineIntervalMs = getOfflineIntervalMs();
37
+ const tickIntervalMs = getTickIntervalMs(process.env);
38
+ const offlineIntervalMs = getOfflineIntervalMs(process.env);
41
39
  // A persistent failure (e.g. Postgres not up yet at container boot) throws
42
40
  // before the loop ever reaches its own `delay`, so `restart: unless-stopped`
43
41
  // would otherwise respawn the process immediately — a tight, log-flooding
@@ -0,0 +1,5 @@
1
+ export { createEmitEvent, type EmitDeps, type EmitEvent } from "../emit.js";
2
+ export { buildAttachmentSweep } from "./attachment-sweep.js";
3
+ export { DEFAULT_OFFLINE_INTERVAL_MS, DEFAULT_TICK_INTERVAL_MS, } from "./config.js";
4
+ export { type CalendarSubscriptionTally, type RunSchedulerTickDeps, runSchedulerTick, type SchedulerTickResult, } from "./run-tick.js";
5
+ export { redriveStrandedPlacements, type StrandedPlacementEvent, type StrandedPlacementRedriveDeps, } from "./stranded-placement-redrive.js";
@@ -0,0 +1,5 @@
1
+ export { createEmitEvent } from "../emit.js";
2
+ export { buildAttachmentSweep } from "./attachment-sweep.js";
3
+ export { DEFAULT_OFFLINE_INTERVAL_MS, DEFAULT_TICK_INTERVAL_MS, } from "./config.js";
4
+ export { runSchedulerTick, } from "./run-tick.js";
5
+ export { redriveStrandedPlacements, } from "./stranded-placement-redrive.js";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@remit/imap-worker",
3
- "version": "0.0.91",
3
+ "version": "0.0.93",
4
4
  "type": "module",
5
5
  "main": "dist/index.js",
6
6
  "exports": {
@@ -16,6 +16,10 @@
16
16
  "types": "./dist/scheduler/handler.d.ts",
17
17
  "default": "./dist/scheduler/handler.js"
18
18
  },
19
+ "./scheduler-tick": {
20
+ "types": "./dist/scheduler/tick.d.ts",
21
+ "default": "./dist/scheduler/tick.js"
22
+ },
19
23
  "./mailbox-management": {
20
24
  "types": "./dist/handlers/mailbox-management.d.ts",
21
25
  "default": "./dist/handlers/mailbox-management.js"