fix(email-connectors): add 10s HTTP timeouts to all adapters and offload bulkExportContacts to background jobs

Đang mở
#58 0 bình luận 0 reaction 0 người được giao Xem trên GitHub

Maintainer thường phản hồi trong vòng 1 ngày

Chưa có ai nhận issue này.

Đánh giá

Độ khó
5/5
Thời gian dự kiến
Hơn một tuần
Mức phù hợp với người mới
25/100
Loại issue
Tính năng
Độ rõ ràng
Đặc tả rõ ràng
Mức độ hoạt động
Sôi nổi
Công nghệ
postgresql, react, typescript

Hướng nghiên cứu

Start with the five adapters under packages/email-connectors/src/adapters/, the DTO and service named in the issue, and the worker job handler at apps/workers/src/services/db-job-poller.ts. Trace the existing export request through the controller and frontend before estimating the queue and status changes. Done means adapter timeouts, contact validation, background processing with progress and completion counts, and a non-blocking export status flow are covered.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

backend bug web workers
Problem Description
  1. No HTTP timeouts in any of the 5 Email Connector adapters:
    In packages/email-connectors/src/adapters/*.adapter.ts (KlaviyoAdapter, MailchimpAdapter, KitAdapter, FlodeskAdapter, ActiveCampaignAdapter), none of the fetch() calls pass an AbortController timeout. If an ESP stalls, dispatchDualWrite, retryFailedSyncs, and bulkExportContacts hang until the OS TCP timeout (2-5 minutes), tying up API concurrency.

  2. Synchronous unbounded bulkExportContacts times out at scale:
    In apps/api/src/email-connectors/email-connectors.service.ts (bulkExportContacts, lines 541-612), POST /email-connectors/bulk-export pushes all contacts synchronously inside the HTTP request lifecycle, and BulkExportContactsDto (apps/api/src/email-connectors/dto/email-connectors.dto.ts, lines 86-107) lacks @IsArray(), @ArrayMaxSize(), and @ValidateNested() validation.
    For 1,000–30,000+ contacts, the HTTP request exceeds reverse-proxy/gateway timeouts (30-60s 504), hits ESP rate limits (429), and forces the user to stay blocked on the page.


Expected Behavior
  1. Every fetch() call in all 5 email adapters enforces a 10-second AbortController timeout (always clearing the timer in finally) and returns a clear retryable error on timeout ("Provider timed out after 10s, please retry").
  2. BulkExportContactsDto.contacts is validated (@IsArray(), @ArrayMaxSize(10000), @ValidateNested({ each: true })).
  3. Large bulk exports run asynchronously in the background without blocking the user's browser or starving real-time DM/comment worker queues.
  4. The user can navigate anywhere immediately after clicking Export, see a non-blocking progress/status indicator, and receive a completion notification with final synced / failed counts.

Where to Look
  • packages/email-connectors/src/adapters/*.adapter.ts (klaviyo, mailchimp, kit, flodesk, activecampaign)
  • apps/api/src/email-connectors/dto/email-connectors.dto.ts (BulkExportContactsDto)
  • apps/api/src/email-connectors/email-connectors.service.ts (bulkExportContacts, dispatchDualWrite, retryFailedSyncs)
  • apps/api/src/email-connectors/email-connectors.controller.ts
  • apps/workers/src/services/db-job-poller.ts (worker job handler)
  • apps/web (bulk export trigger & status toast/notification)

Solution / Implementation Guide (Zero-Breakage Plan)
  1. 10s Timeout Helper Across All 5 Email Adapters (packages/email-connectors):

    • Add a shared fetchWithTimeout(url, init, timeoutMs = 10000) helper using AbortController + try { ... } finally { clearTimeout(timer); }.
    • Catch AbortError cleanly and return { success: false, error: 'Request timed out after 10s. Please retry.' } so existing callers (dispatchDualWrite, testConnection, getAudiences) never crash on unhandled rejections.
  2. DTO Validation (email-connectors.dto.ts):

    • Add @IsArray(), @ArrayMaxSize(10000), @ValidateNested({ each: true }), and @Type(() => BulkExportContactItemDto) on BulkExportContactsDto.contacts.
  3. Background Job Queueing Without Starving DM Workers (apps/api + apps/workers):

    • Enqueue jobType: 'BULK_EMAIL_EXPORT' in BackgroundJob with low priority (priority: 10) so real-time Instagram SEND_DM / comment jobs (priority: 1) always run first.
    • Store only { companyId, userId, connectorId, listId, contacts } in the job payload — never store decrypted API keys in BackgroundJob.payload (the worker decrypts connector credentials at execution time).
    • Process contacts in small rate-limit-safe batches (e.g., 5-10 concurrent with brief pacing and 429 backoff), batch-insert EmailConnectorSyncLog rows via createMany per chunk, and update job progress ({ processed, total, synced, failed }) so GET /email-connectors/bulk-export/:jobId can report progress.
    • When finished, create a Notification for userId / companyId ("Bulk email export complete: X synced, Y failed").
    • Backward compatibility: If contacts.length <= 50, bulkExportContacts can optionally still execute inline and return { synced, failed, errors } immediately, or the controller + frontend can handle { jobId, status: 'QUEUED' } consistently in the same PR.
  4. Non-Blocking Frontend UX (apps/web):

    • On export submit, show a non-blocking toast / subtle background badge ("Exporting contacts in background..."), allow the user to navigate freely, and poll GET /email-connectors/bulk-export/:jobId (or listen for notifications) to surface the final completion toast.
Ngôn ngữ chính
TypeScript
Star
2
Fork
1
Merge trung bình
6 phút
Pull request đã merge (30 ngày)
27

Chuẩn bị môi trường

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của sumamakhan761/tryinstance

Tất cả issue của sumamakhan761/tryinstance

Issue tương tự

Thêm issue về TypeScript

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.