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

Add: UI-Version update checks are only executed, if two subsequent versions don't change

This commit contains a fixup for the original commit 64f2780a
parent 51ad5f9a
No related branches found
No related tags found
No related merge requests found
......@@ -21,6 +21,7 @@ describe('Updates the version', function () {
'/index.html': () => new Response('<html><head></head><body>it\'s me</body></html>', { headers: { 'content-type': 'text/html' } }),
'/meta.json': td.when(td.func()(td.matchers.anything())).thenReturn(
new Response(JSON.stringify({ commitSha: '1' }), { headers: { 'Content-Type': 'application/json' } }),
new Response(JSON.stringify({ commitSha: '2' }), { headers: { 'Content-Type': 'application/json' } }),
new Response(JSON.stringify({ commitSha: '2' }), { headers: { 'Content-Type': 'application/json' } })
)
}
......@@ -46,10 +47,10 @@ describe('Updates the version', function () {
expect(responseBeforeUpdate.statusCode).to.equal(200)
expect(responseBeforeUpdate.headers.version).to.equal('85101541')
const job = await getQueue('update-version').add({})
const newVersion = await job.finished()
expect(newVersion).to.equal('85102502')
// update has only been registered but not executed yet
expect(await getQueue('update-version').add({}).then(job => job.finished())).to.equal('85101541')
// update is executed with the second iteration
expect(await getQueue('update-version').add({}).then(job => job.finished())).to.equal('85102502')
const responseAfterUpdate = await request(app).get('/index.html')
expect(responseAfterUpdate.statusCode).to.equal(200)
......@@ -66,9 +67,12 @@ describe('Updates the version', function () {
// need to do this with dynamic import such that the mocked config is used
await import('../src/create-queues.js').then(({ default: createQueues }) => createQueues())
// pause the queue to prevent any further updates
const queue = getQueue('update-version')
let count = 0
await new Promise(resolve => queue.on('global:completed', (jobId, result) => {
// only resolve when the second job has been completed as the "update" job needs to be executed twice
if (++count === 1) return
// pause the queue to prevent any further updates
queue.pause()
resolve()
}))
......
......@@ -59,7 +59,11 @@ describe('JS files with dependencies contain events', function () {
}
})
await import('../src/version.js').then(({ updateVersionProcessor }) => updateVersionProcessor())
await import('../src/version.js').then(async ({ updateVersionProcessor }) => {
// need to process two times to actually trigger the update
await updateVersionProcessor()
await updateVersionProcessor()
})
const r2 = await request(app).get('/index.html.js')
expect(r2.headers.dependencies).to.equal('other.css')
......
......@@ -62,7 +62,11 @@ describe('Responses contain custom headers', function () {
expect(response.body).to.have.length(2)
config.urls = []
await import('../src/version.js').then(({ updateVersionProcessor }) => updateVersionProcessor())
await import('../src/version.js').then(async ({ updateVersionProcessor }) => {
// need to process two times to actually trigger the update
await updateVersionProcessor()
await updateVersionProcessor()
})
const response2 = await request(app).get('/meta')
expect(response2.body).to.have.length(1)
......
......@@ -81,15 +81,19 @@ export async function updateVersionProcessor () {
const prevProcessedVersion = await redis.client.get(getRedisKey({ name: 'prevProcessedVersion' }))
// that means, that between the previous update processing and this one, there was no version change
if (prevProcessedVersion === fetchedVersion) {
logger.info('[Version] publish update to other nodes.')
redis.pubClient.publish(getRedisKey({ name: 'updateLatestVersion' }), fetchedVersion)
await redis.client.set(getRedisKey({ name: 'latestVersion' }), fetchedVersion)
latestVersion = fetchedVersion
} else {
logger.info(`[Version] do not execute update yet. Store version ${fetchedVersion} as previous version.`)
await redis.client.set(getRedisKey({ name: 'prevProcessedVersion' }), fetchedVersion)
}
} else {
// if redis is disabled, this will only be trigger by a setInterval and not from a redis event
logger.info('[Version] Clear local cache due to version update.')
cache.clear()
latestVersion = fetchedVersion
}
return (latestVersion = fetchedVersion)
return latestVersion
}
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