feat: support ai context
This commit is contained in:
@@ -2,7 +2,7 @@ import {
|
||||
DEFAULT_BATCH_INTERVAL,
|
||||
DEFAULT_BATCH_SIZE,
|
||||
DEFAULT_BATCH_LENGTH,
|
||||
} from "../../config";
|
||||
} from "../config";
|
||||
|
||||
/**
|
||||
* 批处理队列
|
||||
@@ -10,7 +10,7 @@ import {
|
||||
* @param {*} param1
|
||||
* @returns
|
||||
*/
|
||||
const batchQueue = (
|
||||
const BatchQueue = (
|
||||
{ taskFn, ...args },
|
||||
{
|
||||
batchInterval = DEFAULT_BATCH_INTERVAL,
|
||||
@@ -141,7 +141,7 @@ export const getBatchQueue = (args, opts) => {
|
||||
return queueMap.get(key);
|
||||
}
|
||||
|
||||
const queue = batchQueue(args, opts);
|
||||
const queue = BatchQueue(args, opts);
|
||||
queueMap.set(key, queue);
|
||||
return queue;
|
||||
};
|
||||
@@ -150,7 +150,7 @@ export const getBatchQueue = (args, opts) => {
|
||||
* 清除所有任务
|
||||
*/
|
||||
export const clearAllBatchQueue = () => {
|
||||
for (const queue of queueMap.entries()) {
|
||||
for (const queue of queueMap.values()) {
|
||||
queue.destroy();
|
||||
}
|
||||
};
|
||||
|
||||
@@ -8,7 +8,7 @@ import { kissLog } from "./log";
|
||||
* @param {*} _retryInteral
|
||||
* @returns
|
||||
*/
|
||||
const taskPool = (_interval = 100, _limit = 100, _retryInteral = 1000) => {
|
||||
const TaskPool = (_interval = 100, _limit = 100, _retryInteral = 1000) => {
|
||||
const pool = [];
|
||||
const maxRetry = 2; // 最大重试次数
|
||||
let maxCount = _limit; // 最大数量
|
||||
@@ -34,7 +34,7 @@ const taskPool = (_interval = 100, _limit = 100, _retryInteral = 1000) => {
|
||||
if (retry < maxRetry) {
|
||||
const retryTimer = setTimeout(() => {
|
||||
clearTimeout(retryTimer);
|
||||
pool.push({ args, resolve, reject, retry: retry + 1 });
|
||||
pool.push({ fn, args, resolve, reject, retry: retry + 1 });
|
||||
}, _retryInteral);
|
||||
} else {
|
||||
reject(err);
|
||||
@@ -85,7 +85,7 @@ let fetchPool;
|
||||
*/
|
||||
export const getFetchPool = (interval, limit) => {
|
||||
if (!fetchPool) {
|
||||
fetchPool = taskPool(
|
||||
fetchPool = TaskPool(
|
||||
interval ?? DEFAULT_FETCH_INTERVAL,
|
||||
limit ?? DEFAULT_FETCH_LIMIT
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user