Bắt đầu#

Kiến trúc#

Tool server thứ 3 (VPS worker) giao tiếp với dịch vụ giao việc (assign) qua HTTP. Assign đọc/ghi DB Postgres, phân phối task về đúng server theo services[], xử lý vòng đời task + AI content.

Tool (worker) ──HTTP──> Assign ──bun/Postgres──> likepion_beta

Base URL#

https://assign.likepion.com/api/v1

(đặt theo domain của container assign; xem phần deploy)

Xác thực#

Gửi API Key trong header X-API-Key của mỗi request.

  • API Key lấy từ cột api_key của record trong bảng servers tương ứng với máy chủ tool.
  • Mỗi server phải có status='online'services[] chứa ít nhất 1 loại dịch vụ (ví dụ: {entity_normal}, {link_cloud}, {blog_20}…).
  • Middleware xác thực sẽ reject nếu key sai, server đã deleted_at hoặc không tìm thấy.
  • Context sau xác thực chứa server_id, server_name cho handler.

Response format#

Thành công:

{
  "success": true,
  "data": {}
}

Lỗi:

{
  "success": false,
  "message": "Mô tả lỗi"
}

HTTP Status Codes#

CodeÝ nghĩa
200Thành công
400Request không hợp lệ
401API Key thiếu hoặc sai / server đã xoá
500Lỗi hệ thống (DB, query)

Luồng chuẩn của tool#

1. Gửi heartbeat   : POST /worker/health         (mỗi 30-60s)
2. Pull task       : GET  /worker/tasks?limit=N  (claim atomic → running)
3. Xử lý task      : (đăng ký profile / đăng bài / tạo cloud page...)
4. Báo kết quả     : POST /worker/tasks/:id/complete  (thành công)
                    hoặc POST /worker/tasks/:id/fail (thất bại)
5. Gửi log         : POST /worker/logs                (batch, tuỳ chọn)

Mỗi response task có trường service_type + type_request — tool nên echo lại 2 field này trong body của complete/fail để assign update đúng 1 bảng (nhanh hơn scan 11 bảng).