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

Aperta
#53 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
4/5
Tempo stimato
3-5 giorni
Idoneità per principianti
55/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
postgresql, typescript

Direzione di ricerca

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.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

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'.
Lingua principale
TypeScript
Stelle
2
Fork
1
Merge medio
6m
PR unite (30g)
27

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di sumamakhan761/tryinstance

Tutte le issue di sumamakhan761/tryinstance

Issue simili

Altre issue su TypeScript

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.