Skip to content

feat: real-time job status via Server-Sent Events#1

Merged
orangecoding merged 15 commits intomasterfrom
feat/sse-job-status
Apr 28, 2026
Merged

feat: real-time job status via Server-Sent Events#1
orangecoding merged 15 commits intomasterfrom
feat/sse-job-status

Conversation

@orangecoding
Copy link
Copy Markdown
Owner

Summary

  • Add a global SSE endpoint (GET /api/events) that broadcasts run:started and run:finished events to all connected browser tabs using a singleton EventEmitter bus
  • Job list status badges update live (Running → Success/Failed) without any manual refresh, for both manually triggered and scheduler-triggered runs
  • Run history panel auto-refreshes when a run finishes; reopening the same job's history always fetches fresh data

Changes

Server

  • server/src/services/eventBus.js — singleton EventEmitter (with setMaxListeners(0) for unbounded SSE clients)
  • server/src/scheduler/executor.js — emits run:started / run:finished on the bus
  • server/src/app.js — new GET /api/events SSE route with socket-level cleanup, writableEnded guard, and X-Accel-Buffering: no for Nginx
  • server/src/middleware/gatewayToken.js — accepts token from ?token= query param (EventSource cannot set custom headers)

Client

  • client/src/hooks/useJobEvents.js — new hook: one EventSource per app lifetime, ref-based callbacks to avoid stale closures
  • client/src/hooks/useJobs.js — adds updateRunStarted / updateRunFinished state setters
  • client/src/hooks/useRunHistory.js — adds handleRunFinished for SSE-driven panel refresh
  • client/src/App.jsx — lifts useRunHistory, wires useJobEvents
  • client/src/components/runs/RunHistoryPanel.jsx — now a pure presentational component (data via props)

Test Plan

  • Trigger a job manually — status badge changes to "Running" immediately, then "Success"/"Failed" when done
  • Wait for a scheduled job to fire — badge updates without any user action
  • Open run history panel, trigger a job — new run record appears automatically when it finishes
  • Click history button for the same job twice — list refreshes on second click
  • Kill and restart the dev server — browser auto-reconnects and resumes receiving events

🤖 Generated with Claude Code

@orangecoding orangecoding merged commit a2e6b84 into master Apr 28, 2026
1 check passed
@orangecoding orangecoding deleted the feat/sse-job-status branch April 28, 2026 18:09
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.

1 participant