chore(fe2): more redis logging
This commit is contained in:
Родитель
ff5c965df9
Коммит
f3e8bf7045
|
@ -2,6 +2,8 @@ import type { NuxtApp } from '#app'
|
|||
import type { Optional } from '@speckle/shared'
|
||||
import { buildFakePinoLogger } from '~~/lib/core/helpers/observability'
|
||||
|
||||
export type AppLogger = ReturnType<typeof useLogger>
|
||||
|
||||
export const useLogger = () => {
|
||||
return useNuxtApp().$logger
|
||||
}
|
||||
|
|
|
@ -8,10 +8,26 @@ let redis: InstanceType<typeof Redis> | undefined = undefined
|
|||
/**
|
||||
* Provide redis (only in SSR)
|
||||
*/
|
||||
export default defineNuxtPlugin(() => {
|
||||
export default defineNuxtPlugin(async () => {
|
||||
const { redisUrl } = useRuntimeConfig()
|
||||
if (!redis) {
|
||||
redis = redisUrl?.length ? new Redis(redisUrl) : undefined
|
||||
const logger = useLogger()
|
||||
|
||||
const hasValidStatus =
|
||||
redis && ['ready', 'connecting', 'reconnecting'].includes(redis.status)
|
||||
if (!redis || !hasValidStatus) {
|
||||
if (redis) {
|
||||
await redis.quit()
|
||||
}
|
||||
|
||||
redis = new Redis(redisUrl)
|
||||
|
||||
redis.on('error', (err) => {
|
||||
logger.error(err, 'Redis error')
|
||||
})
|
||||
|
||||
redis.on('end', () => {
|
||||
logger.info('Redis disconnected from server')
|
||||
})
|
||||
}
|
||||
|
||||
return {
|
||||
|
|
Загрузка…
Ссылка в новой задаче