mirror of
https://github.com/labring/FastGPT.git
synced 2025-07-23 05:12:39 +00:00
Perf: vector queue and app ui (#1750)
This commit is contained in:
@@ -1,17 +1,24 @@
|
||||
import { addLog } from '../system/log';
|
||||
import { connectionMongo, ClientSession } from './index';
|
||||
|
||||
export const mongoSessionRun = async <T = unknown>(fn: (session: ClientSession) => Promise<T>) => {
|
||||
const session = await connectionMongo.startSession();
|
||||
let committed = false;
|
||||
|
||||
try {
|
||||
session.startTransaction();
|
||||
const result = await fn(session);
|
||||
|
||||
await session.commitTransaction();
|
||||
committed = true;
|
||||
|
||||
return result as T;
|
||||
} catch (error) {
|
||||
await session.abortTransaction();
|
||||
if (!committed) {
|
||||
await session.abortTransaction();
|
||||
} else {
|
||||
addLog.warn('Un catch mongo session error', { error });
|
||||
}
|
||||
return Promise.reject(error);
|
||||
} finally {
|
||||
await session.endSession();
|
||||
|
Reference in New Issue
Block a user