feat(queue): integrate Asynq + Redis Streams for background jobs and event-driven messaging#28
Conversation
…events Adds a full background-job and event-streaming layer backed by the existing Redis instance (REDIS_URL) — no new env vars required. - usecase.Enqueuer interface (Enqueue + Close) in usecase/enqueuer.go - internal/infrastructure/queue/: Asynq client, worker, task constants, WelcomeEmail handler stub (real delivery wired in #20) - internal/infrastructure/streams/: Redis Streams producer + consumer-group consumer for event fan-out (user.created, notification.sent) - bootstrap.App gains an Enqueuer field (nil when REDIS_URL is unset) - Handler struct gains enqueuer + queueUI fields; Asynqmon UI mounts at /admin/queues in debug mode when Redis is available - Worker goroutine wired in main.go following the ws.Hub pattern; cancelled before hub on graceful shutdown - Queue unit tests (handlers_test.go) run without Docker; integration test skips gracefully when Docker is unavailable - Stale docs fixed: routing.md (NewServer signature + /metrics route), middleware.md (SentryMiddleware + PrometheusMiddleware order) - New docs: backend/docs/queue.md, backend/docs/streams.md Closes #18 Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
|
Warning Review limit reached
More reviews will be available in 2 minutes and 20 seconds. Learn how PR review limits work. Your organization has run out of usage credits. Purchase more credits in the billing tab to continue. ⌛ How to resolve this issue?After more reviews become available, a review can be triggered using the We recommend that you space out your commits to avoid hitting the rate limit. 🚦 How do rate limits work?CodeRabbit enforces hourly rate limits for each developer per organization. Our paid plans include higher PR review limits than trial, open-source, and free plans. In all cases, reviews become available again over time. During sustained high-volume PR review activity, CodeRabbit may temporarily slow when the next review becomes available. Please see our Fair Usage Limits Policy for further information. ℹ️ Review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: ⛔ Files ignored due to path filters (1)
📒 Files selected for processing (27)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Summary
usecase.Enqueuerinterface (Enqueue,Close) — the queue port, nil-safe when Redis is unavailableinternal/infrastructure/queue/— Asynq client, worker,TypeWelcomeEmailtask constant + handler stub (real Mailjet delivery wired in feat: integrate Mailjet for transactional email (SMTP) #20); Asynqmon UI at/admin/queuesin debug modeinternal/infrastructure/streams/— Redis StreamsProducer(XADD) and consumer-groupConsumer(XREADGROUP+XACK) for event fan-out (stream:user.created,stream:notification.sent)bootstrap.AppgainsEnqueuerfield (nil whenREDIS_URLunset — no new env vars)main.gofollowing thews.Hubpattern; cancelled before hub on graceful shutdownrouting.md(NewServersignature,/metricsroute),middleware.md(middleware chain order)backend/docs/queue.md,backend/docs/streams.mdCloses #18
Test plan
go vet ./...— cleango test ./internal/infrastructure/queue/...— unit tests pass; integration test skips without Docker, passes with Dockergo test ./internal/transport/...— all handler and middleware tests passREDIS_URLset: worker starts,GET /admin/queuesreturns Asynqmon UITypeWelcomeEmailtask and verify it appears in worker logsUserCreatedEventtostream:user.createdand verifyXRangeshows the entryREDIS_URL: server starts normally, queue/streams features silently disabled