Skip to content

Commit

Permalink
fix(chat): Fixed chat feature support for older Redis versions
Browse files Browse the repository at this point in the history
  • Loading branch information
andris9 committed Oct 6, 2023
1 parent 2ca325a commit 86538ba
Showing 1 changed file with 13 additions and 5 deletions.
18 changes: 13 additions & 5 deletions workers/documents.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ const crypto = require('crypto');

const { readEnvValue, threadStats, getDuration } = require('../lib/tools');

const GB_COLLECT_DELAY = 100; // 6 * 3600 * 1000; // 6h
const GB_COLLECT_DELAY = 6 * 3600 * 1000; // 6h
const GB_FAILURE_DELAY = 3 * 1000;
const GB_EMPTY_DELAY = 10 * 1000;

Expand Down Expand Up @@ -940,11 +940,18 @@ documentsWorker.on('failed', async job => {
});

const clearExpungedEmbeddings = async () => {
const { index, client } = await getESClient(logger);
if (!(await redis.exists(`${REDIS_PREFIX}expungequeue`))) {
// nothing to do here
await new Promise(resolve => {
let timer = setTimeout(resolve, GB_EMPTY_DELAY);
timer.unref();
});
return;
}

let rangeEnd = Date.now() - GB_COLLECT_DELAY;
try {
let expungedEntry = await redis.zrange(`${REDIS_PREFIX}expungequeue`, 0, rangeEnd, 'BYSCORE', 'LIMIT', '0', '1');

let expungedEntry = await redis.zrangebyscore(`${REDIS_PREFIX}expungequeue`, 0, rangeEnd, 'LIMIT', '0', '1');
if (!expungedEntry?.length) {
await new Promise(resolve => {
let timer = setTimeout(resolve, GB_EMPTY_DELAY);
Expand Down Expand Up @@ -978,8 +985,9 @@ const clearExpungedEmbeddings = async () => {
}
};

let existingResult;
const { index, client } = await getESClient(logger);

let existingResult;
try {
existingResult = await client.search({
index,
Expand Down

0 comments on commit 86538ba

Please sign in to comment.