feat(server): add BullMQ queue and worker with Redis#1
feat(server): add BullMQ queue and worker with Redis#1JoaoPixelCode wants to merge 3 commits intomainfrom
Conversation
JoaoPixelCode
commented
Mar 4, 2026
- Adicionado Redis no docker-compose
- Criado queue.ts com a fila de mensagens
- Criado worker.ts para processar as mensagens
- Adicionado rota /api/queue no servidor
- Adicionado REDIS_URL nas variáveis de ambiente
There was a problem hiding this comment.
Pull request overview
This PR introduces Redis-backed background processing to the server using BullMQ, adding a queue, a worker to consume jobs, and an API endpoint to enqueue messages.
Changes:
- Add
REDIS_URLto server environment validation and introduce BullMQ as a dependency. - Create
chatQueue(queue.ts) andchatWorker(worker.ts) wired to Redis. - Add Redis service to
docker-compose.ymland expose a newPOST /api/queueroute to enqueue jobs.
Reviewed changes
Copilot reviewed 6 out of 7 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| packages/env/src/server.ts | Adds REDIS_URL to required server env vars. |
| package.json | Adds BullMQ dependency at repo root. |
| package-lock.json | Locks BullMQ and transitive dependencies. |
| docker-compose.yml | Adds Redis service and a (currently unused) redis volume declaration. |
| apps/server/src/queue.ts | Defines the BullMQ queue instance for chat jobs. |
| apps/server/src/worker.ts | Defines the BullMQ worker to process chat jobs. |
| apps/server/src/index.ts | Wires queue route and starts worker via side-effect import. |
Comments suppressed due to low confidence (5)
apps/server/src/index.ts:116
/api/queuedestructuresmessagedirectly fromreq.body, which will throw if the body is missing/invalid (e.g., empty request). It also enqueues potentially non-string/blank messages. Align validation with/api/chat(treat body as unknown, validatemessageis a non-empty string, and return 400 on invalid input).
app.post("/api/queue", async (req, res) => {
const { message } = req.body;
await chatQueue.add("chat-message", { message });
apps/server/src/index.ts:5
- Importing
./workerfrom the main server entrypoint starts the BullMQ worker inside every API process. In production this can unintentionally scale workers with web replicas (and makes API availability depend on Redis/worker connectivity). Consider running the worker in a separate process/entrypoint, or gating worker startup behind an env flag (e.g.,RUN_WORKER=true).
import { chatQueue } from "./queue";
import "./worker";
apps/server/src/worker.ts:19
chatWorkeris created at module load and never closed. Add graceful shutdown handling (SIGINT/SIGTERM) to callchatWorker.close()(and any related Redis connections) so containers can terminate cleanly and not hang during deploys/restarts.
export const chatWorker = new Worker(
"chat",
async (job) => {
console.log(`Processando mensagem: ${job.data.message}`);
// Aqui vai entrar futuramente:
// 1. Buscar no banco vetorial (RAG)
// 2. Mandar pra IA
// 3. Retornar a resposta
},
{
connection: {
url: env.REDIS_URL,
},
},
);
docker-compose.yml:81
ifinho-redis-datavolume is declared but theredisservice does not mount it, so Redis data will be ephemeral. Either mount the volume under the Redis service (e.g.,/data) or remove the unused volume declaration to avoid confusion.
volumes:
ifinho-postgres-data:
ifinho-ollama-data:
ifinho-redis-data:
package.json:26
bullmqis added to the rootpackage.json, but it is only imported byapps/server. To keep workspace dependency graphs accurate (and avoid relying on hoisting), addbullmqtoapps/server/package.jsondependencies and remove it from the root if nothing else uses it.
"@ifinho/env": "*",
"bullmq": "^5.70.1",
"dotenv": "^17.2.2",
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
You can also share your feedback on Copilot code review. Take the survey.
| redis: | ||
| container_name: ifinho-redis | ||
| image: redis:7-alpine | ||
| restart: unless-stopped | ||
| ports: | ||
| - "6379:6379" | ||
| networks: | ||
| - ifinho-network |
There was a problem hiding this comment.
Redis was added, but the server container is not being given REDIS_URL and does not depend on redis. Since @ifinho/env/server now requires REDIS_URL, the server will fail to start under this compose file. Add REDIS_URL to the server.environment (e.g., redis://ifinho-redis:6379) and consider adding a depends_on/healthcheck for Redis.
|
o BullMQ não suporta postgres apenas redis, então por conta disso não vamos usar ele e sim o pg-boss para essa parte de jobs e message queue |