Jobs · Module Overview

Jobs — BullMQ workers và tác vụ nền

Trang này giải thích jobs là gì, ai cần đọc nó, và những file nào quyết định hành vi chính.

Mục đích

Module jobs gom toàn bộ pipeline bất đồng bộ: email, Bloom filter, vector search, full-text search, like sync, notification debounce, AI evaluation, giảm HP circle và tự gỡ ban.

Về mặt kỹ thuật, module này bám pattern route -> controller -> service -> repository. Những việc chậm hoặc phụ thuộc service ngoài được đẩy sang Redis/BullMQ khi code có producer tương ứng.

Phạm vi

Trong phạm vi ✓Ngoài phạm vi ✗
Các endpoint dưới workersUI frontend và copy hiển thị trong app
Validation, business rules, side effects từ codeÝ định product không thể thấy trong source
DB/cache/queue/service ngoài module gọi trực tiếpSLA chính thức nếu không có trong config/code

Công nghệ & thư viện sử dụng

Thành phầnCông nghệPhiên bảnLý do chọnGhi chú
HTTPExpress5.1.0Router/middleware rõ ràngpackage.json
ValidationZod3.25.76Validate request trước controllerRoute nào có validate() mới enforce
DBPrisma + MySQL/MariaDBPrisma 7Repository truy cập databaseschema.prisma
AsyncBullMQ + RedisBullMQ 5Tách tác vụ nềnKhông phải module nào cũng enqueue

Cấu trúc file

Sơ đồ này cho thấy module được chia theo vai trò: route nhận URL, controller đọc request, service quyết định nghiệp vụ, repository chạm database.

routesentrypointcontrollerrequest/responseservicebusiness rulesrepositoryPrisma/MySQLdtoZod validationcallscallsqueriesvalidate
Đây là cấu trúc lặp lại trong hầu hết module, không dùng thư viện vẽ ngoài.
1
workers/index.ts

File này là một phần của luồng jobs. Đọc nó để trace request từ entrypoint tới nghiệp vụ.

snippet định vị
// đọc file này để trace module jobs
import ... from "workers/index.ts"
2
workers/evaluate.worker.ts

File này là một phần của luồng jobs. Đọc nó để trace request từ entrypoint tới nghiệp vụ.

snippet định vị
// đọc file này để trace module jobs
import ... from "workers/evaluate.worker.ts"
3
workers/like.worker.ts

File này là một phần của luồng jobs. Đọc nó để trace request từ entrypoint tới nghiệp vụ.

snippet định vị
// đọc file này để trace module jobs
import ... from "workers/like.worker.ts"
4
workers/notification.worker.ts

File này là một phần của luồng jobs. Đọc nó để trace request từ entrypoint tới nghiệp vụ.

snippet định vị
// đọc file này để trace module jobs
import ... from "workers/notification.worker.ts"
5
workers/message.worker.ts

File này là một phần của luồng jobs. Đọc nó để trace request từ entrypoint tới nghiệp vụ.

snippet định vị
// đọc file này để trace module jobs
import ... from "workers/message.worker.ts"
6
src/server.ts

File này là một phần của luồng jobs. Đọc nó để trace request từ entrypoint tới nghiệp vụ.

snippet định vị
// đọc file này để trace module jobs
import ... from "src/server.ts"

Dependency map

Module này dùng các dependency ở bên trái và có thể được module bên phải gọi hoặc phụ thuộc gián tiếp.

jobsmoduleDepends onredis, bullmq, prismaUsed byauth, post, circleStorage/ExternalDB Redis APIsOutputsresponse/eventsusescalledreads/writesemits
Mũi tên đi vào là dependency module dùng; mũi tên đi ra là nơi kết quả được tiêu thụ.

Tóm tắt luồng chính

Request đồng bộ enqueue job; worker lấy job từ Redis/BullMQ, gọi service ngoài hoặc DB, rồi cập nhật dữ liệu phụ trợ.