@@ -152,6 +152,7 @@ erDiagram
152152 User ||--o{ DailyActivity : has
153153 User ||--o{ ManualHighlight : has
154154 User ||--o{ PublicShare : has
155+ User ||--o{ SyncJob : has
155156
156157 User {
157158 string id PK
@@ -198,13 +199,44 @@ erDiagram
198199 datetime expiresAt
199200 datetime revokedAt
200201 }
202+
203+ SyncJob {
204+ string id PK
205+ string userId FK
206+ enum provider NULL
207+ datetime from NULL
208+ datetime to NULL
209+ int backfillYear NULL
210+ enum status
211+ int attemptCount
212+ int maxAttempts
213+ datetime availableAt
214+ datetime lockedAt NULL
215+ datetime startedAt NULL
216+ datetime finishedAt NULL
217+ string errorMessage NULL
218+ datetime createdAt
219+ datetime updatedAt
220+ }
201221```
202222
203223### Privacy boundaries in data model
204224- ` Integration ` keeps encrypted secrets only.
205225- ` DailyActivity ` is aggregate-only.
226+ - ` SyncJob ` stores orchestration metadata only (no provider raw payloads, no repo names, no commit messages).
206227- No model stores repository names or commit messages.
207228
229+ ### Supabase sync job lifecycle (when ` SYNC_QUEUE_BACKEND=supabase ` )
230+ - ` QUEUED ` : job waiting for processing (` availableAt <= now ` means runnable).
231+ - ` RUNNING ` : worker has lock and is executing provider sync.
232+ - ` COMPLETED ` : sync finished successfully, ` finishedAt ` set.
233+ - ` FAILED ` : retries exhausted or non-retryable failure, ` errorMessage ` recorded.
234+
235+ Retry/backoff behavior:
236+ - ` attemptCount ` increments when a worker locks a queued job.
237+ - if ` attemptCount < maxAttempts ` , job is re-queued with future ` availableAt ` .
238+ - backoff is exponential and capped (current implementation caps at 60 seconds).
239+
208240---
209241
210242## API architecture
@@ -316,7 +348,7 @@ npm run worker:nightly
316348` worker:nightly ` registers the repeatable nightly sync schedule. Run it once per environment.
317349
318350### Supabase queue mode (no Redis worker required)
319- If you want to run without BullMQ/Redis for low-cost environments:
351+ Replace BullMQ/Redis solution for low-cost environments:
320352
3213531 . Set:
322354``` bash
@@ -332,7 +364,7 @@ POST /api/internal/sync/process
332364Authorization: Bearer < CRON_SECRET>
333365```
334366
335- You can process manually :
367+ Process manually in dev :
336368``` bash
337369npm run queue:process
338370```
@@ -346,10 +378,10 @@ select
346378 $$
347379 select
348380 net .http_post (
349- url := ' https://YOUR_APP_DOMAIN /api/internal/sync/process?limit=10' ,
381+ url := ' https://contribution-pulse.vercel.app /api/internal/sync/process?limit=10' ,
350382 headers := jsonb_build_object(
351383 ' Content-Type' , ' application/json' ,
352- ' Authorization' , ' Bearer YOUR_CRON_SECRET '
384+ ' Authorization' , ' Bearer CRON_SECRET '
353385 ),
354386 body := ' {}' ::jsonb
355387 );
@@ -372,7 +404,7 @@ Current automated tests include:
372404
373405---
374406
375- ## Deployment topology (recommended)
407+ ## Deployment topology
3764081 . Web service: Next.js app
3774092 . Worker service: BullMQ worker process
3784103 . Scheduler service/job: ` worker:nightly ` (or one-time bootstrap)
@@ -381,30 +413,6 @@ Current automated tests include:
381413
382414---
383415
384- ## CI/CD and release architecture
385-
386- ### GitHub Actions workflows
387- - ` CI ` -> ` .github/workflows/ci.yml `
388- - triggers on push to ` main ` and pull requests
389- - runs dependency install, Prisma client generation, tests, and production build
390- - ` Deploy to Vercel ` -> ` .github/workflows/vercel-deploy.yml `
391- - triggers on push to ` main ` and manual dispatch
392- - runs ` vercel pull ` , ` vercel build ` , ` vercel deploy --prebuilt `
393-
394- ### CI/CD pipeline diagram
395- ``` mermaid
396- flowchart LR
397- DEV[Developer Push/PR] --> GHA1[GitHub Actions: CI]
398- GHA1 --> T1[npm ci]
399- T1 --> T2[prisma generate]
400- T2 --> T3[vitest]
401- T3 --> T4[next build]
402- T4 -->|main only| GHA2[GitHub Actions: Vercel Deploy]
403- GHA2 --> V1[vercel pull]
404- V1 --> V2[vercel build --prod]
405- V2 --> V3[vercel deploy --prebuilt --prod]
406- V3 --> PROD[Vercel Production]
407- ```
408416
409417### Required GitHub repository secrets
410418Set these in GitHub repo settings -> Secrets and variables -> Actions:
@@ -466,14 +474,3 @@ docker compose down
466474- Run ` npm run worker:nightly ` once per environment to register the repeatable nightly sync schedule.
467475
468476---
469-
470- ## Known constraints and next scaling steps
471- - Current worker loops integrations sequentially per user job.
472- - Redis pub/sub publisher currently opens per-publish connection (can be pooled).
473- - Nightly sync processes all users in one scheduler-triggered workflow.
474-
475- Recommended next steps:
476- - provider-level job fan-out for large tenants
477- - shared Redis connection pooling for event publish
478- - metrics/tracing (OpenTelemetry)
479- - dead-letter queue and alerting for repeated sync failures
0 commit comments