Skip to content

Feature/job state model - #32

Open
Rhea-15 wants to merge 13 commits into
madhav2348:developfrom
Rhea-15:feature/job-state-model
Open

Feature/job state model#32
Rhea-15 wants to merge 13 commits into
madhav2348:developfrom
Rhea-15:feature/job-state-model

Conversation

@Rhea-15

@Rhea-15 Rhea-15 commented Jun 7, 2026

Copy link
Copy Markdown
Contributor

Summary
Defines a standardised Job interface and JobStatus state machine with enforced forward-only transitions, per-stage error tracking and typed timestamps.

Issue ticket number and link
Closes #18

Changes

  • src/server/types/queue.ts — added Job interface with startedAt, completedAt, stageErrors; added JobStatus, PipelineStage types; added isValidTransition() to enforce queued → processing → processed | failed (retry resets failed → queued only); added JobView serialisable shape and toJobView() helper; kept original QueueJob alias for backwards compat
  • src/server/services/queue/queue.ts — internal store switched to Map<string, Job>; updateStatus() guards every transition via isValidTransition() and logs a warning on invalid attempts; sets startedAt on first processing entry and completedAt on terminal states; records per-stage errors in stageErrors; retry() only succeeds from failed state; added list(), listViews() with optional ?status= filter
  • src/app/api/screenshots/route.ts — GET now returns job list via queue.listViews() with optional ?status= query param filter; POST unchanged except returns typed job.status
  • src/app/api/screenshots/[jobId]/route.ts — returns full JobView including startedAt, completedAt, stageErrors
  • src/server/runtime.ts — updated queue instantiation to use new InMemoryQueue signature

Testing
[x]Tested locally

  • GET /api/screenshots returns [] on fresh start
  • POST /api/screenshots with a file returns {"jobId": "job_...", "status": "queued"}
  • GET /api/screenshots/[jobId] returns full JobView shape with stageErrors: {}
  • GET /api/screenshots?status=queued returns the job correctly
  • GET /api/screenshots?status=processed returns [] when no completed jobs exist
  • Ran a manual transition test via a temporary route confirming: startedAt is set on processing, completedAt is set on both processed and failed, stageErrors records per-stage error detail, invalid transition (processed → queued) was blocked and state remained processed
  • npm run backend:check, npm run lint, npm run build all pass

Checklist before requesting a review

[x]Code follows the project's TypeScript style conventions
[x] No secrets or .env values are committed
[x]I have performed a self-review of my code
[x]CI passes

@github-actions

github-actions Bot commented Jun 7, 2026

Copy link
Copy Markdown

🎉 Thanks for submitting a PR, @Rhea-15!

Please confirm the following checklist before review:

  • ⭐ I have starred this repository
  • 🍴 I have forked this repository
  • 📖 I have read the Contributing Guidelines
  • 🔀 My changes are pushed to the develop branch

A maintainer will review your PR shortly. Thank you! 🚀

@madhav2348

Copy link
Copy Markdown
Owner

@Rhea-15 please resolve the merce conflict,

@Rhea-15

Rhea-15 commented Jun 7, 2026

Copy link
Copy Markdown
Contributor Author

@madhav2348 done resolving the merge conflicts

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants