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:
@@ -368,5 +368,6 @@ runTests().catch((error) => {
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -309,5 +309,6 @@ runTest()
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -347,5 +347,6 @@ Content-Type: application/json
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -257,7 +257,7 @@ async function processScreeningBatchWithCheckpoint(
|
||||
literature.publicationYear ? Number(literature.publicationYear) : undefined
|
||||
);
|
||||
|
||||
// 保存结果(使用 screeningService.ts 相同的映射方式)
|
||||
// 保存结果(使用 upsert 保证幂等性,任务重试时覆盖而不是重复创建)
|
||||
const dbResult = {
|
||||
projectId,
|
||||
literatureId: literature.id,
|
||||
@@ -294,8 +294,16 @@ async function processScreeningBatchWithCheckpoint(
|
||||
finalDecision: screeningResult.finalDecision,
|
||||
};
|
||||
|
||||
await prisma.aslScreeningResult.create({
|
||||
data: dbResult,
|
||||
// 🛡️ 使用 upsert 实现幂等性(利用 unique_project_literature 约束)
|
||||
await prisma.aslScreeningResult.upsert({
|
||||
where: {
|
||||
projectId_literatureId: {
|
||||
projectId,
|
||||
literatureId: literature.id,
|
||||
},
|
||||
},
|
||||
create: dbResult,
|
||||
update: dbResult,
|
||||
});
|
||||
|
||||
successCount++;
|
||||
|
||||
@@ -67,12 +67,8 @@ export function registerResearchWorker() {
|
||||
error: error.message,
|
||||
});
|
||||
|
||||
// 更新任务状态为失败
|
||||
try {
|
||||
await researchService.executeSearch(taskId, query);
|
||||
} catch {
|
||||
// 忽略
|
||||
}
|
||||
// ❌ 已移除错误的 executeSearch 调用
|
||||
// 任务失败后 pg-boss 会自动重试(最多3次)
|
||||
|
||||
return {
|
||||
success: false,
|
||||
|
||||
Reference in New Issue
Block a user