fix: update meta cache between workers
Some checks failed
ci/woodpecker/push/lint-backend Pipeline failed
ci/woodpecker/push/lint-foundkey-js Pipeline was successful
ci/woodpecker/push/lint-client Pipeline failed
ci/woodpecker/push/build Pipeline was successful
ci/woodpecker/push/lint-sw Pipeline failed
ci/woodpecker/push/test Pipeline failed

This commit is contained in:
Johann150 2023-05-12 19:34:08 +02:00
parent e6c7f4b693
commit 386d1bbf74
Signed by: Johann150
GPG key ID: 9EE6577A2A06F8F1
2 changed files with 21 additions and 0 deletions

View file

@ -168,6 +168,15 @@ function spawnWorker(mode: 'web' | 'queue'): Promise<void> {
case 'ready': case 'ready':
res(); res();
break; break;
case 'metaUpdate':
// forward new instance metadata to all workers
for (const otherWorker of Object.values(cluster.workers)) {
// don't forward the message to the worker that sent it
if (worker.id === otherWorker.id) continue;
otherWorker.send(message);
}
break;
} }
}); });
}); });

View file

@ -1,3 +1,4 @@
import process from 'node:process';
import push from 'web-push'; import push from 'web-push';
import { db } from '@/db/postgre.js'; import { db } from '@/db/postgre.js';
import { Meta } from '@/models/entities/meta.js'; import { Meta } from '@/models/entities/meta.js';
@ -17,9 +18,20 @@ export async function setMeta(meta: Meta): Promise<void> {
cache = meta; cache = meta;
/*
The meta is not included here because another process may have updated
the content before the other process receives it.
*/
process.send!('metaUpdated');
unlock(); unlock();
} }
// the primary will forward this message
process.on('message', async message => {
if (message === 'metaUpdated') await getMeta();
});
/** /**
* Performs the primitive database operation to fetch server configuration. * Performs the primitive database operation to fetch server configuration.
* If there is no entry yet, inserts a new one. * If there is no entry yet, inserts a new one.