mirror of
https://github.com/labring/FastGPT.git
synced 2025-10-17 16:45:02 +00:00

* feat: workflow catch error (#5220) * feat: error catch * feat: workflow catch error * perf: add catch error to node * feat: system tool error catch * catch error * fix: ts * update doc * perf: training queue code (#5232) * doc * perf: training queue code * Feat: 优化错误提示与重试逻辑 (#5192) * feat: 批量重试异常数据 & 报错信息国际化 - 新增“全部重试”按钮,支持批量重试所有训练异常数据 - 报错信息支持国际化,常见错误自动映射为 i18n key - 相关文档和 i18n 资源已同步更新 * feat: enhance error message and retry mechanism * feat: enhance error message and retry mechanism * feat: add retry_failed i18n key * feat: enhance error message and retry mechanism * feat: enhance error message and retry mechanism * feat: enhance error message and retry mechanism : 5 * feat: enhance error message and retry mechanism : 6 * feat: enhance error message and retry mechanism : 7 * feat: enhance error message and retry mechanism : 8 * perf: catch chat error * perf: copy hook (#5246) * perf: copy hook * doc * doc * add app evaluation (#5083) * add app evaluation * fix * usage * variables * editing condition * var ui * isplus filter * migrate code * remove utils * name * update type * build * fix * fix * fix * delete comment * fix * perf: eval code * eval code * eval code * feat: ttfb time in model log * Refactor chat page (#5253) * feat: update side bar layout; add login and logout logic at chat page * refactor: encapsulate login logic and reuse it in `LoginModal` and `Login` page * chore: improve some logics and comments * chore: improve some logics * chore: remove redundant side effect; add translations --------- Co-authored-by: Archer <545436317@qq.com> * perf: chat page code * doc * perf: provider redirect * chore: ui improvement (#5266) * Fix: SSE * Fix: SSE * eval pagination (#5264) * eval scroll pagination * change eval list to manual pagination * number * fix build * fix * version doc (#5267) * version doc * version doc * doc * feat: eval model select * config eval model * perf: eval detail modal ui * doc * doc * fix: chat store reload * doc --------- Co-authored-by: colnii <1286949794@qq.com> Co-authored-by: heheer <heheer@sealos.io> Co-authored-by: 酒川户 <76519998+chuanhu9@users.noreply.github.com>
81 lines
2.4 KiB
TypeScript
81 lines
2.4 KiB
TypeScript
import { getQueue, getWorker, QueueNames } from '../../../common/bullmq';
|
|
import { type Processor } from 'bullmq';
|
|
import { addLog } from '../../../common/system/log';
|
|
|
|
export type EvaluationJobData = {
|
|
evalId: string;
|
|
};
|
|
|
|
export const evaluationQueue = getQueue<EvaluationJobData>(QueueNames.evaluation, {
|
|
defaultJobOptions: {
|
|
attempts: 3,
|
|
backoff: {
|
|
type: 'exponential',
|
|
delay: 1000
|
|
}
|
|
}
|
|
});
|
|
|
|
const concurrency = process.env.EVAL_CONCURRENCY ? Number(process.env.EVAL_CONCURRENCY) : 3;
|
|
export const getEvaluationWorker = (processor: Processor<EvaluationJobData>) => {
|
|
return getWorker<EvaluationJobData>(QueueNames.evaluation, processor, {
|
|
removeOnFail: {
|
|
count: 1000 // Keep last 1000 failed jobs
|
|
},
|
|
concurrency: concurrency
|
|
});
|
|
};
|
|
|
|
export const addEvaluationJob = (data: EvaluationJobData) => {
|
|
const evalId = String(data.evalId);
|
|
|
|
return evaluationQueue.add(evalId, data, { deduplication: { id: evalId } });
|
|
};
|
|
|
|
export const checkEvaluationJobActive = async (evalId: string): Promise<boolean> => {
|
|
try {
|
|
const jobId = await evaluationQueue.getDeduplicationJobId(String(evalId));
|
|
if (!jobId) return false;
|
|
|
|
const job = await evaluationQueue.getJob(jobId);
|
|
if (!job) return false;
|
|
|
|
const jobState = await job.getState();
|
|
return ['waiting', 'delayed', 'prioritized', 'active'].includes(jobState);
|
|
} catch (error) {
|
|
addLog.error('Failed to check evaluation job status', { evalId, error });
|
|
return false;
|
|
}
|
|
};
|
|
|
|
export const removeEvaluationJob = async (evalId: string): Promise<boolean> => {
|
|
const formatEvalId = String(evalId);
|
|
try {
|
|
const jobId = await evaluationQueue.getDeduplicationJobId(formatEvalId);
|
|
if (!jobId) {
|
|
addLog.warn('No job found to remove', { evalId });
|
|
return false;
|
|
}
|
|
|
|
const job = await evaluationQueue.getJob(jobId);
|
|
if (!job) {
|
|
addLog.warn('Job not found in queue', { evalId, jobId });
|
|
return false;
|
|
}
|
|
|
|
const jobState = await job.getState();
|
|
|
|
if (['waiting', 'delayed', 'prioritized'].includes(jobState)) {
|
|
await job.remove();
|
|
addLog.info('Evaluation job removed successfully', { evalId, jobId, jobState });
|
|
return true;
|
|
} else {
|
|
addLog.warn('Cannot remove active or completed job', { evalId, jobId, jobState });
|
|
return false;
|
|
}
|
|
} catch (error) {
|
|
addLog.error('Failed to remove evaluation job', { evalId, error });
|
|
return false;
|
|
}
|
|
};
|