forked from labring/FastGPT
-
Notifications
You must be signed in to change notification settings - Fork 34
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* timer lock * update iframe.js * fix: timer lock and http histories * fix: tool module connection type * file icon * doc * fix: index decod * update laf module * doc * laf env config
- Loading branch information
Showing
52 changed files
with
2,531 additions
and
2,523 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
export enum TimerIdEnum { | ||
checkInValidDatasetFiles = 'checkInValidDatasetFiles', | ||
checkInvalidDatasetData = 'checkInvalidDatasetData', | ||
checkInvalidVector = 'checkInvalidVector', | ||
clearExpiredSubPlan = 'clearExpiredSubPlan', | ||
updateStandardPlan = 'updateStandardPlan' | ||
} | ||
|
||
export const timerIdMap = { | ||
[TimerIdEnum.checkInValidDatasetFiles]: 'checkInValidDatasetFiles', | ||
[TimerIdEnum.checkInvalidDatasetData]: 'checkInvalidDatasetData', | ||
[TimerIdEnum.checkInvalidVector]: 'checkInvalidVector', | ||
[TimerIdEnum.clearExpiredSubPlan]: 'clearExpiredSubPlan', | ||
[TimerIdEnum.updateStandardPlan]: 'updateStandardPlan' | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import { connectionMongo, type Model } from '../../mongo'; | ||
import { timerIdMap } from './constants'; | ||
const { Schema, model, models } = connectionMongo; | ||
import { TimerLockSchemaType } from './type.d'; | ||
|
||
export const collectionName = 'systemtimerlocks'; | ||
|
||
const TimerLockSchema = new Schema({ | ||
timerId: { | ||
type: String, | ||
required: true, | ||
unique: true, | ||
enum: Object.keys(timerIdMap) | ||
}, | ||
expiredTime: { | ||
type: Date, | ||
required: true | ||
} | ||
}); | ||
|
||
try { | ||
TimerLockSchema.index({ expiredTime: 1 }, { expireAfterSeconds: 5 }); | ||
} catch (error) { | ||
console.log(error); | ||
} | ||
|
||
export const MongoTimerLock: Model<TimerLockSchemaType> = | ||
models[collectionName] || model(collectionName, TimerLockSchema); | ||
MongoTimerLock.syncIndexes(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
export type TimerLockSchemaType = { | ||
_id: string; | ||
timerId: string; | ||
expiredTime: Date; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import { TimerIdEnum } from './constants'; | ||
import { MongoTimerLock } from './schema'; | ||
import { addMinutes } from 'date-fns'; | ||
|
||
/* | ||
利用唯一健,使得同一时间只有一个任务在执行,后创建的锁,会因唯一健创建失败,从而无法继续执行任务 | ||
*/ | ||
export const checkTimerLock = async ({ | ||
timerId, | ||
lockMinuted | ||
}: { | ||
timerId: `${TimerIdEnum}`; | ||
lockMinuted: number; | ||
}) => { | ||
try { | ||
await MongoTimerLock.create({ | ||
timerId, | ||
expiredTime: addMinutes(new Date(), lockMinuted) | ||
}); | ||
|
||
return true; | ||
} catch (error) { | ||
return false; | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.