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

Clear the cache on version update

parent c9d89ba0
No related branches found
No related tags found
No related merge requests found
...@@ -2,6 +2,7 @@ import fetch from 'node-fetch' ...@@ -2,6 +2,7 @@ import fetch from 'node-fetch'
import { config } from './config.js' import { config } from './config.js'
import { getRedisKey, hash } from './util.js' import { getRedisKey, hash } from './util.js'
import { logger } from './logger.js' import { logger } from './logger.js'
import * as cache from './cache.js'
import * as redis from './redis.js' import * as redis from './redis.js'
let latestVersion let latestVersion
...@@ -49,15 +50,16 @@ export async function getLatestVersion () { ...@@ -49,15 +50,16 @@ export async function getLatestVersion () {
} }
export function registerLatestVersionListener (client) { export function registerLatestVersionListener (client) {
if (redis.isEnabled()) { if (!redis.isEnabled()) return
const key = getRedisKey({ name: 'updateLatestVersion' })
client.subscribe(key, (errs, count) => logger.info(`[Redis] Subscribed to ${key}.`)) const key = getRedisKey({ name: 'updateLatestVersion' })
client.on('message', async (channel, message) => { client.subscribe(key, (errs, count) => logger.info(`[Redis] Subscribed to ${key}.`))
if (channel !== key) return client.on('message', async (channel, message) => {
await config.load() if (channel !== key) return
latestVersion = message await config.load()
}) cache.clear()
} latestVersion = message
})
} }
export async function updateVersionProcessor () { export async function updateVersionProcessor () {
...@@ -70,6 +72,9 @@ export async function updateVersionProcessor () { ...@@ -70,6 +72,9 @@ export async function updateVersionProcessor () {
if (redis.isEnabled()) { if (redis.isEnabled()) {
redis.pubClient.publish(getRedisKey({ name: 'updateLatestVersion' }), fetchedVersion) redis.pubClient.publish(getRedisKey({ name: 'updateLatestVersion' }), fetchedVersion)
await redis.client.set(getRedisKey({ name: 'latestVersion' }), fetchedVersion) await redis.client.set(getRedisKey({ name: 'latestVersion' }), fetchedVersion)
} else {
// if redis is disabled, this will only be trigger by a setInterval and not from a redis event
cache.clear()
} }
return (latestVersion = fetchedVersion) return (latestVersion = fetchedVersion)
} }
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