feat(platform): Fix pg-boss queue conflict and add safety standards

Summary:
- Fix pg-boss queue conflict (duplicate key violation on queue_pkey)
- Add global error listener to prevent process crash
- Reduce connection pool from 10 to 4
- Add graceful shutdown handling (SIGTERM/SIGINT)
- Fix researchWorker recursive call bug in catch block
- Make screeningWorker idempotent using upsert

Security Standards (v1.1):
- Prohibit recursive retry in Worker catch blocks
- Prohibit payload bloat (only store fileKey/ID in job.data)
- Require Worker idempotency (upsert + unique constraint)
- Recommend task-specific expireInSeconds settings
- Document graceful shutdown pattern

New Features:
- PKB signed URL endpoint for document preview/download
- pg_bigm installation guide for Docker
- Dockerfile.postgres-with-extensions for pgvector + pg_bigm

Documentation:
- Update Postgres-Only async task processing guide (v1.1)
- Add troubleshooting SQL queries
- Update safety checklist

Tested: Local verification passed
This commit is contained in:
2026-01-23 22:07:26 +08:00
parent 9c96f75c52
commit 61cdc97eeb
297 changed files with 1147 additions and 21 deletions

View File

@@ -0,0 +1,54 @@
# PostgreSQL 15 with pgvector + pg_bigm extensions
# 用于 AI 临床研究平台的向量检索和中文关键词检索
#
# 扩展版本:
# - pgvector: 0.8.1 (向量相似度搜索)
# - pg_bigm: 1.2 (中日韩文本全文搜索)
#
# 构建命令:
# docker build -f Dockerfile.postgres-with-extensions -t ai-clinical-postgres:v1.1 .
#
# 使用方法:
# 1. 构建镜像后,修改 docker-compose.yml:
# image: ai-clinical-postgres:v1.1
# 2. 重启服务docker compose down && docker compose up -d
# 3. 启用扩展:
# docker exec -it ai-clinical-postgres psql -U postgres -d ai_clinical_research -c "CREATE EXTENSION IF NOT EXISTS pg_bigm;"
FROM pgvector/pgvector:pg15
# 使用阿里云镜像源加速(如果在国内)
# RUN sed -i 's/deb.debian.org/mirrors.aliyun.com/g' /etc/apt/sources.list.d/*.sources 2>/dev/null || true
# 安装编译依赖
RUN apt-get update && apt-get install -y --no-install-recommends \
build-essential \
postgresql-server-dev-15 \
wget \
ca-certificates \
&& rm -rf /var/lib/apt/lists/*
# 下载并编译 pg_bigm
# pg_bigm 是专门为中日韩CJK字符优化的全文搜索扩展
RUN cd /tmp \
&& wget -q https://github.com/pgbigm/pg_bigm/archive/refs/tags/v1.2-20200228.tar.gz \
&& tar -xzf v1.2-20200228.tar.gz \
&& cd pg_bigm-1.2-20200228 \
&& make USE_PGXS=1 \
&& make USE_PGXS=1 install \
&& cd / \
&& rm -rf /tmp/pg_bigm* /tmp/v1.2-20200228.tar.gz
# 清理编译依赖
RUN apt-get purge -y --auto-remove \
build-essential \
postgresql-server-dev-15 \
wget \
&& rm -rf /var/lib/apt/lists/*
# 添加初始化脚本(自动创建扩展)
COPY docker-init-extensions.sql /docker-entrypoint-initdb.d/
# 暴露端口
EXPOSE 5432