Skip to content
Snippets Groups Projects
Commit 9b026d1b authored by julian.baeume's avatar julian.baeume :pick:
Browse files

move cache warmup into readiness check

this will mark the pod "ready", once the cache is warm.
This will remove the penality for the very first to this service, because
it will not receive any traffic until the cache is warm.
parent 33708934
No related branches found
No related tags found
No related merge requests found
...@@ -44,6 +44,7 @@ describe('File caching service', () => { ...@@ -44,6 +44,7 @@ describe('File caching service', () => {
'/main.css': (req, res) => res.setHeader('content-type', 'text/css').status(200).send('.foo { color: #000; }') '/main.css': (req, res) => res.setHeader('content-type', 'text/css').status(200).send('.foo { color: #000; }')
}) })
await request(app).get('/ready')
}) })
afterEach(() => { afterEach(() => {
......
...@@ -35,6 +35,15 @@ export function createApp () { ...@@ -35,6 +35,15 @@ export function createApp () {
const httpLogger = pinoHttp({ logger, autoLogging: { ignorePaths } }) const httpLogger = pinoHttp({ logger, autoLogging: { ignorePaths } })
const healthCheck = new health.HealthChecker() const healthCheck = new health.HealthChecker()
const readinessCheck = new health.ReadinessCheck('getDependencies', async function () {
try {
await getDependencies()
} catch (e) {
logger.error(`Failed to get dependencies: ${e.message}`)
throw e
}
})
healthCheck.registerReadinessCheck(readinessCheck)
// Application-level middleware // Application-level middleware
app.use(httpLogger) app.use(httpLogger)
...@@ -70,14 +79,12 @@ export function createApp () { ...@@ -70,14 +79,12 @@ export function createApp () {
}) })
app.get('/', async (req, res, next) => { app.get('/', async (req, res, next) => {
await getDependencies()
const { 'content-type': contentType, content } = fileCache.get('/index.html') const { 'content-type': contentType, content } = fileCache.get('/index.html')
if (content) return res.setHeader('content-type', contentType).status(200).send(content) if (content) return res.setHeader('content-type', contentType).status(200).send(content)
next() next()
}) })
app.use(async (req, res, next) => { app.use(async (req, res, next) => {
await getDependencies()
const { 'content-type': contentType, content } = fileCache.get(req.path) const { 'content-type': contentType, content } = fileCache.get(req.path)
if (content) return res.setHeader('content-type', contentType).status(200).send(content) if (content) return res.setHeader('content-type', contentType).status(200).send(content)
next() next()
......
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