perf: queue link

This commit is contained in:
archer
2023-06-17 21:27:44 +08:00
parent 61447c60ac
commit 00c93a63cd
8 changed files with 14 additions and 66 deletions

View File

@@ -19,34 +19,10 @@ export async function generateVector(): Promise<any> {
let userId = '';
try {
const match = {
mode: TrainingModeEnum.index,
lockTime: { $lte: new Date(Date.now() - 2 * 60 * 1000) }
};
// random get task
const agree = await TrainingData.aggregate([
{
$match: match
},
{ $sample: { size: 1 } },
{
$project: {
_id: 1
}
}
]);
// no task
if (agree.length === 0) {
reduceQueue();
global.vectorQueueLen <= 0 && console.log(`没有需要【索引】的数据, ${global.vectorQueueLen}`);
return;
}
const data = await TrainingData.findOneAndUpdate(
{
_id: agree[0]._id,
...match
mode: TrainingModeEnum.index,
lockTime: { $lte: new Date(Date.now() - 2 * 60 * 1000) }
},
{
lockTime: new Date()
@@ -63,7 +39,8 @@ export async function generateVector(): Promise<any> {
// task preemption
if (!data) {
reduceQueue();
return generateVector();
global.vectorQueueLen <= 0 && console.log(`没有需要【索引】的数据, ${global.vectorQueueLen}`);
return;
}
trainingId = data._id;