Skip to content

feat(queue): integrate Asynq + Redis Streams for background jobs and event-driven messaging#28

Merged
GRACENOBLE merged 1 commit into
mainfrom
feat/18-asynq-redis-streams
Jun 15, 2026
Merged

feat(queue): integrate Asynq + Redis Streams for background jobs and event-driven messaging#28
GRACENOBLE merged 1 commit into
mainfrom
feat/18-asynq-redis-streams

Conversation

@GRACENOBLE

Copy link
Copy Markdown
Owner

Summary

  • usecase.Enqueuer interface (Enqueue, Close) — the queue port, nil-safe when Redis is unavailable
  • internal/infrastructure/queue/ — Asynq client, worker, TypeWelcomeEmail task constant + handler stub (real Mailjet delivery wired in feat: integrate Mailjet for transactional email (SMTP) #20); Asynqmon UI at /admin/queues in debug mode
  • internal/infrastructure/streams/ — Redis Streams Producer (XADD) and consumer-group Consumer (XREADGROUP + XACK) for event fan-out (stream:user.created, stream:notification.sent)
  • bootstrap.App gains Enqueuer field (nil when REDIS_URL unset — no new env vars)
  • Worker goroutine wired in main.go following the ws.Hub pattern; cancelled before hub on graceful shutdown
  • Queue unit tests run without Docker; integration test skips cleanly when Docker is unavailable
  • Fixed stale docs: routing.md (NewServer signature, /metrics route), middleware.md (middleware chain order)
  • New docs: backend/docs/queue.md, backend/docs/streams.md

Closes #18

Test plan

  • go vet ./... — clean
  • go test ./internal/infrastructure/queue/... — unit tests pass; integration test skips without Docker, passes with Docker
  • go test ./internal/transport/... — all handler and middleware tests pass
  • Start with REDIS_URL set: worker starts, GET /admin/queues returns Asynqmon UI
  • Enqueue a TypeWelcomeEmail task and verify it appears in worker logs
  • Publish a UserCreatedEvent to stream:user.created and verify XRange shows the entry
  • Start without REDIS_URL: server starts normally, queue/streams features silently disabled

…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>
@github-actions github-actions Bot added area: backend Go REST API type: chore Cleanup or maintenance tasks labels Jun 15, 2026
@GRACENOBLE GRACENOBLE merged commit 58f52df into main Jun 15, 2026
3 checks passed
@GRACENOBLE GRACENOBLE deleted the feat/18-asynq-redis-streams branch June 15, 2026 15:25
@coderabbitai

coderabbitai Bot commented Jun 15, 2026

Copy link
Copy Markdown

Warning

Review limit reached

@GRACENOBLE, we couldn't start this review because you've reached your PR review rate limit.

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 @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

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 configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 9a80a0ce-726d-4534-a01a-dedc8a6de7b3

📥 Commits

Reviewing files that changed from the base of the PR and between 99c064f and 94c8d6b.

⛔ Files ignored due to path filters (1)
  • backend/go.sum is excluded by !**/*.sum
📒 Files selected for processing (27)
  • backend/cmd/api/main.go
  • backend/docs/_index.md
  • backend/docs/middleware.md
  • backend/docs/queue.md
  • backend/docs/routing.md
  • backend/docs/streams.md
  • backend/docs/swagger/docs.go
  • backend/docs/swagger/swagger.json
  • backend/docs/swagger/swagger.yaml
  • backend/go.mod
  • backend/internal/bootstrap/bootstrap.go
  • backend/internal/infrastructure/queue/client.go
  • backend/internal/infrastructure/queue/client_test.go
  • backend/internal/infrastructure/queue/handlers.go
  • backend/internal/infrastructure/queue/handlers_test.go
  • backend/internal/infrastructure/queue/tasks.go
  • backend/internal/infrastructure/queue/worker.go
  • backend/internal/infrastructure/streams/consumer.go
  • backend/internal/infrastructure/streams/events.go
  • backend/internal/infrastructure/streams/producer.go
  • backend/internal/infrastructure/streams/producer_test.go
  • backend/internal/server/server.go
  • backend/internal/transport/handlers/handler.go
  • backend/internal/transport/handlers/health_handler_test.go
  • backend/internal/transport/handlers/queue_handler.go
  • backend/internal/transport/handlers/routes.go
  • backend/internal/usecase/enqueuer.go
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/18-asynq-redis-streams

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

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

Labels

area: backend Go REST API type: chore Cleanup or maintenance tasks

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat: integrate Asynq + Redis Streams for background jobs and event-driven messaging

1 participant