Skip to content

OUT-4024: Move resync mechanisms to trigger.dev - #75

Merged
SandipBajracharya merged 4 commits into
mainfrom
OUT-4024
Sep 2, 2026
Merged

OUT-4024: Move resync mechanisms to trigger.dev#75
SandipBajracharya merged 4 commits into
mainfrom
OUT-4024

Conversation

@SandipBajracharya

Copy link
Copy Markdown
Collaborator

What & why

Closes OUT-4024.

The failed-sync retry ran as a Vercel cron (/cron/retry-failed-syncs) whose handler executed the whole retry loop inline under a 300s function maxDuration. As failed records grow, that sequential loop risks timing out and never draining the backlog.

This moves the retry off Vercel and onto a trigger.dev native scheduled task (cron every 6h, 3600s max duration). trigger.dev owns the schedule end-to-end, so the Vercel cron, route, and controller are removed entirely. RetryFailedSyncsService itself is unchanged — just relocated.

Changes

  • src/trigger/resyncFailedRecords.tsschedules.task (cron: '0 */6 * * *', machine: 'small-2x') that calls RetryFailedSyncsService.retryFailedSyncs().
  • trigger.config.ts — mirrors the quickbooks-sync setup: maxDuration: 3600, task-level retries, Sentry source-map upload + init + onFailure.
  • Removed the Vercel cron route, its controller, the vercel.json cron entry, and the now-orphaned CRON_SECRET env var.
  • Added @trigger.dev/sdk, @trigger.dev/build, @sentry/esbuild-plugin and trigger:dev / trigger:deploy scripts.

server-only stub (repo-specific)

trigger.config.ts stubs the server-only marker to an empty module in the esbuild build. Unlike quickbooks-sync, this repo's service chain imports server-only (via server.env, db, CopilotAPI, …), which throws when bundled outside Next's react-server condition and would crash the trigger worker at boot. Verified empirically that the bundle throws without the stub and loads with it.

Verification

  • pnpm typecheck (app + test) ✅
  • pnpm lint
  • Integration tests exercise RetryFailedSyncsService directly and are unaffected (not run here — needs Docker/testcontainers).
  • A full pnpm trigger:dev smoke test still needs the trigger.dev project + env vars below.

Deploy checklist (before go-live)

  • Set TRIGGER_PROJECT_ID and TRIGGER_SECRET_KEY
  • Run pnpm trigger:deploy to register the scheduled task
  • Populate trigger.dev's env store with the app runtime vars (COPILOT_API_KEY, DATABASE_URL, XERO_*, ASSEMBLY_ENV) plus VERCEL_ENV=production and the Sentry vars (NEXT_PUBLIC_SENTRY_DSN, SENTRY_ORG, SENTRY_PROJECT, SENTRY_AUTH_TOKEN) — in both the deploy context and the runtime store

🤖 Generated with Claude Code

SandipBajracharya and others added 3 commits September 1, 2026 19:38
Add @trigger.dev/sdk, @trigger.dev/build and @sentry/esbuild-plugin
along with trigger:dev / trigger:deploy scripts, and ignore the local
.trigger cache directory.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Move the failed-sync retry loop off the 300s Vercel function onto a
trigger.dev scheduled task (cron every 6h, 3600s max duration), so it
no longer times out as failed records grow. The task reuses the
existing RetryFailedSyncsService unchanged.

trigger.config.ts mirrors the quickbooks-sync setup (Sentry source-map
upload, init and onFailure capture). It also stubs the `server-only`
marker to an empty module in the esbuild build: unlike quickbooks-sync,
this repo's service chain imports `server-only`, which throws when
bundled outside Next's react-server condition and would crash the
trigger worker at boot.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
trigger.dev now owns the resync schedule, so remove the Vercel cron
entry, the /cron/retry-failed-syncs route and its controller, and the
now-orphaned CRON_SECRET env var (its only consumer was that route).

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@linear-code

linear-code Bot commented Sep 1, 2026

Copy link
Copy Markdown

OUT-4024

@vercel

vercel Bot commented Sep 1, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
xero-integration Ready Ready Preview Sep 2, 2026 7:57am UTC

Request Review

@supabase

supabase Bot commented Sep 1, 2026

Copy link
Copy Markdown

This pull request has been ignored for the connected project pkdwtcdqcefmlgxmcwmc because there are no changes detected in supabase directory. You can change this behaviour in Project Integrations Settings ↗︎.


Preview Branches by Supabase.
Learn more about Supabase Branching ↗︎.

@greptile-apps

greptile-apps Bot commented Sep 1, 2026

Copy link
Copy Markdown

Greptile Summary

The PR moves failed-sync recovery from a Vercel HTTP cron to a Trigger.dev scheduled task, extending the available execution time while retaining the existing retry service.

  • Adds a six-hour Trigger.dev scheduled task and worker configuration.
  • Adds Trigger.dev build/runtime dependencies, deployment scripts, and Sentry integration.
  • Removes the Vercel cron route, controller, schedule, and obsolete cron secret.

Confidence Score: 5/5

The PR appears safe to merge, with no concrete changed-code defect identified.

The new scheduler delegates to the unchanged recovery service, and the removed Vercel entry point is replaced coherently by the Trigger.dev task and documented deployment requirements.

Important Files Changed

Filename Overview
src/trigger/resyncFailedRecords.ts Defines the new scheduled entry point and delegates recovery to the existing retry service.
trigger.config.ts Configures the Trigger.dev Node worker, retries, build extensions, environment validation, and Sentry reporting.
src/features/failed-syncs/api/failedSyncs.controller.ts Removes the obsolete authenticated HTTP controller now that recovery is initiated by Trigger.dev.
src/app/cron/retry-failed-syncs/route.ts Removes the former Vercel cron route and its five-minute execution boundary.
vercel.json Removes the superseded two-hour Vercel cron schedule.
package.json Adds pinned Trigger.dev commands and the dependencies required to build and run the worker.

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart LR
  A[Trigger.dev six-hour schedule] --> B[processResyncForFailedRecords]
  B --> C[RetryFailedSyncsService]
  C --> D[Select eligible failed records]
  D --> E[Replay through WebhookService]
  E -->|Success| F[Delete failed record]
  E -->|Failure| G[Retain record and increment attempts]
Loading

Reviews (1): Last reviewed commit: "refactor(OUT-4024): drop vercel cron ret..." | Re-trigger Greptile

@priosshrsth priosshrsth left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lgtm

@SandipBajracharya
SandipBajracharya merged commit 6bf9d9f into main Sep 2, 2026
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants