fallback to worker redis client if fetched content not found in cache

This commit is contained in:
Hongbo Wu
2024-01-30 12:27:45 +08:00
parent a94b6717d9
commit e724bbd465

View File

@ -139,13 +139,18 @@ const sendImportStatusUpdate = async (
const getCachedFetchResult = async (url: string) => {
const key = `fetch-result:${url}`
if (!redisDataSource.redisClient) {
if (!redisDataSource.redisClient || !redisDataSource.workerRedisClient) {
throw new Error('redis client is not initialized')
}
const result = await redisDataSource.redisClient.get(key)
let result = await redisDataSource.redisClient.get(key)
if (!result) {
throw new Error('fetch result is not cached')
logger.debug(`fetch result is not cached in cache redis ${url}`)
// fallback to worker redis client if the result is not found
result = await redisDataSource.workerRedisClient.get(key)
if (!result) {
throw new Error('fetch result is not cached')
}
}
const fetchResult = JSON.parse(result) as unknown