fix(posting): cap stuck Instagram container polling and guard scheduled post create/update transitions

Đang mở
#53 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ó
4/5
Thời gian dự kiến
3-5 ngày
Mức phù hợp với người mới
55/100
Loại issue
Lỗi
Độ rõ ràng
Đặc tả rõ ràng
Mức độ hoạt động
Sôi nổi
Công nghệ
postgresql, typescript
Lĩnh vực
backend, database, devops

Hướng nghiên cứu

Read apps/workers/src/services/db-job-poller.ts and apps/workers/src/services/instagram-api.service.ts to trace ContainerNotReadyError retries and job state updates, then inspect apps/api/src/instagram/services/instagram-posts.service.ts for create and update flows. Check the existing worker and service tests before changing behavior. Done means polling eventually fails with a clear error, post and job creation is atomic, and edits are rejected during PROCESSING.

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

Mô tả

backend bug workers
Problem Description
  1. Infinite reschedule loop on stuck Instagram media containers:
    In apps/workers/src/services/instagram-api.service.ts (waitForContainerAndPublish, lines 789-815), an IN_PROGRESS media container throws ContainerNotReadyError(containerId, 5).
    In apps/workers/src/services/db-job-poller.ts (lines 272-295), catching ContainerNotReadyError resets attempts: candidate.attempts with no maximum poll count or elapsed-time cap. If an Instagram container gets stuck in IN_PROGRESS (e.g., corrupt or rejected video), the worker polls Graph API indefinitely every ~6-12s while leaving InstagramScheduledPost.status stuck in PROCESSING.

  2. Non-atomic post/job creation and unsafe edits during PROCESSING:

    • In apps/api/src/instagram/services/instagram-posts.service.ts (createScheduledPost, lines 226-264), instagramScheduledPost.create and backgroundJob.create run outside a prisma.$transaction; if backgroundJob.create fails, an orphaned post remains in SCHEDULED / PROCESSING with backgroundJobId: null.
    • updateScheduledPost (lines 278-356) only rejects PUBLISHED posts, allowing edits while post.status === 'PROCESSING' and resetting the BackgroundJob back to PENDING mid-publish, risking duplicate publishes.

Expected Behavior
  1. Container polling (ContainerNotReadyError) must have a safe maximum cap (e.g., 15-20 minutes or max ~100 polls so large ~100 MB videos have plenty of time to process), after which both BackgroundJob and InstagramScheduledPost transition to FAILED with a clear timeout error.
  2. createScheduledPost must create the InstagramScheduledPost and BackgroundJob atomically inside prisma.$transaction.
  3. updateScheduledPost must continue allowing edits while SCHEDULED, and reject edits while status === 'PROCESSING' (in addition to PUBLISHED).

Where to Look
  • apps/workers/src/services/instagram-api.service.ts (waitForContainerAndPublish, lines 789-815)
  • apps/workers/src/services/db-job-poller.ts (lines 272-295)
  • apps/api/src/instagram/services/instagram-posts.service.ts (createScheduledPost lines 226-264, updateScheduledPost lines 278-356)

Solution / Implementation Guide
  1. Cap container polling (db-job-poller.ts & publish-worker.ts):
    • Track containerPollCount and firstPolledAt in err.updatedPayload when handling ContainerNotReadyError.
    • Once containerPollCount >= MAX_CONTAINER_POLLS (e.g., 100) or Date.now() - firstPolledAt > 20 * 60 * 1000, mark both the BackgroundJob and InstagramScheduledPost as FAILED with a descriptive errorMessage instead of rescheduling.
  2. Atomic create & PROCESSING edit guard (instagram-posts.service.ts):
    • Wrap instagramScheduledPost.create, backgroundJob.create, and linking backgroundJobId inside this.prisma.$transaction(...) in createScheduledPost.
    • In updateScheduledPost, reject requests with 409 Conflict / 400 BadRequest when existing.status === 'PROCESSING'.
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.