seperating batch payload from job queue

This commit is contained in:
Boki 2025-06-10 09:58:20 -04:00
parent c57733ebca
commit b974753d8b
5 changed files with 360 additions and 25 deletions

View file

@ -253,6 +253,44 @@ export class RedisCache implements CacheProvider {
return this.get<number[]>(key);
}
async waitForReady(timeout: number = 5000): Promise<void> {
if (this.isConnected) {
return Promise.resolve();
}
return new Promise((resolve, reject) => {
const timeoutId = setTimeout(() => {
reject(new Error(`Redis cache connection timeout after ${timeout}ms`));
}, timeout);
const onReady = () => {
clearTimeout(timeoutId);
this.redis.off('ready', onReady);
this.redis.off('error', onError);
resolve();
};
const onError = (error: Error) => {
clearTimeout(timeoutId);
this.redis.off('ready', onReady);
this.redis.off('error', onError);
reject(new Error(`Redis cache connection failed: ${error.message}`));
};
if (this.redis.status === 'ready') {
clearTimeout(timeoutId);
resolve();
} else {
this.redis.once('ready', onReady);
this.redis.once('error', onError);
}
});
}
isReady(): boolean {
return this.isConnected && this.redis.status === 'ready';
}
/**
* Close the Redis connection
*/