fix: 多机部署,导致任务重复

This commit is contained in:
archer
2023-04-17 10:41:35 +08:00
parent 647f701692
commit 7e54421190
4 changed files with 49 additions and 4 deletions

View File

@@ -13,7 +13,12 @@ import { ModelSplitDataSchema } from '@/types/mongoSchema';
const nanoid = customAlphabet('abcdefghijklmnopqrstuvwxyz1234567890', 12);
export async function generateQA(next = false): Promise<any> {
if (process.env.queueTask !== '1') {
fetch(process.env.parentUrl || '');
return;
}
if (global.generatingQA === true && !next) return;
global.generatingQA = true;
let dataId = null;
@@ -165,8 +170,13 @@ export async function generateQA(next = false): Promise<any> {
console.log('生成QA错误:', error);
}
if (dataId && error?.response?.data?.error?.type === 'insufficient_quota') {
console.log('api 余额不足');
// 没有余额或者凭证错误时,拒绝任务
if (
dataId &&
(+error.response?.status === 401 ||
error?.response?.data?.error?.type === 'insufficient_quota')
) {
console.log('api 异常删除QA任务');
await SplitData.findByIdAndUpdate(dataId, {
textList: [],