mirror of
https://github.com/labring/FastGPT.git
synced 2025-07-23 05:12:39 +00:00

* rebuild embedding queue * dataset menu * feat: rebuild data api * feat: ui change embedding model * dataset ui * feat: rebuild index ui * rename collection
20 lines
520 B
TypeScript
20 lines
520 B
TypeScript
import { connectionMongo, ClientSession } from './index';
|
|
|
|
export const mongoSessionRun = async <T = unknown>(fn: (session: ClientSession) => Promise<T>) => {
|
|
const session = await connectionMongo.startSession();
|
|
session.startTransaction();
|
|
|
|
try {
|
|
const result = await fn(session);
|
|
|
|
await session.commitTransaction();
|
|
await session.endSession();
|
|
|
|
return result as T;
|
|
} catch (error) {
|
|
await session.abortTransaction();
|
|
await session.endSession();
|
|
return Promise.reject(error);
|
|
}
|
|
};
|