Skip to content
Snippets Groups Projects
Commit 73d3ec20 authored by richard.petersen's avatar richard.petersen :sailboat:
Browse files

fix: OXUIB-2001 - Service doesn't recover from missing Redis service

root cause: When redis was not available, some files could not be saved in the local memory and therefore this error permanently occurs even though the node responded correctly.
solution: Improve robustness when redis is not available
parent 71f8e589
No related branches found
No related tags found
No related merge requests found
......@@ -16,7 +16,7 @@ export function set (key, value) {
if (cache[key] === value) return
cache[key] = value
if (redis.isEnabled()) {
return redis.client.set(key, value)
return redis.client.set(key, value).catch(err => logger.error(err))
}
}
......@@ -35,7 +35,7 @@ export function get (key, fallback) {
const promise = (async () => {
if (redis.isEnabled()) {
let result = await redis.client.get(key)
let result = await redis.client.get(key).catch(err => logger.error(err))
if (result) {
logger.debug(`[Cache] Resolve from redis: ${key}`)
result = JSON.parse(result)
......@@ -50,7 +50,7 @@ export function get (key, fallback) {
if (fallbackResult) {
logger.debug(`[Cache] Found a getter for: ${key}`)
cache[key] = fallbackResult
if (redis.isEnabled()) redis.client.set(key, JSON.stringify(fallbackResult))
if (redis.isEnabled()) redis.client.set(key, JSON.stringify(fallbackResult)).catch(err => logger.error(err))
}
return fallbackResult
})()
......@@ -79,7 +79,10 @@ export function getFile ({ name, version }, fallback) {
const [body, meta = '{}'] = await Promise.all([
redis.client.getBuffer(bodyKey),
redis.client.get(metaKey)
])
]).catch((err) => {
logger.error(`[Cache] could not access redis: ${err}`)
return []
})
if (body) {
logger.debug(`[Cache] Resolve file from redis: ${key}`)
......@@ -96,8 +99,8 @@ export function getFile ({ name, version }, fallback) {
if (redis.isEnabled()) {
logger.debug(`[Cache] Store file in redis: ${key}`)
const { body, ...rest } = dataFromServer
redis.client.set(bodyKey, createWritable(body))
redis.client.set(metaKey, JSON.stringify(rest))
redis.client.set(bodyKey, createWritable(body)).catch(err => logger.error(`[Cache] could not store ${bodyKey}: ${err}`))
redis.client.set(metaKey, JSON.stringify(rest)).catch(err => logger.error(`[Cache] could not store ${metaKey}: ${err}`))
}
// overwrite cache with synchronous data
......
......@@ -9,8 +9,8 @@ const createClient = (type, options = {}) => {
if (!isEnabled()) {
return new Proxy({
getBuffer () {},
get () {},
set () {},
get () { return Promise.resolve() },
set () { return Promise.resolve() },
del () {},
flushdb () { return {} },
status: '',
......@@ -47,7 +47,7 @@ export async function isReady () {
}).catch(() => false)
}
export const client = createClient('common client')
export const client = createClient('common client', { maxRetriesPerRequest: 1 })
export const pubClient = createClient('pub client')
export const subClient = createClient('sub client', commonQueueOptions)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment