diff --git a/packages/backend/src/boot/master.ts b/packages/backend/src/boot/master.ts index a688a8ae6..6f64715f8 100644 --- a/packages/backend/src/boot/master.ts +++ b/packages/backend/src/boot/master.ts @@ -168,6 +168,15 @@ function spawnWorker(mode: 'web' | 'queue'): Promise { case 'ready': res(); 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; } }); }); diff --git a/packages/backend/src/misc/fetch-meta.ts b/packages/backend/src/misc/fetch-meta.ts index ab8c81eef..da71b1d4b 100644 --- a/packages/backend/src/misc/fetch-meta.ts +++ b/packages/backend/src/misc/fetch-meta.ts @@ -1,3 +1,4 @@ +import process from 'node:process'; import push from 'web-push'; import { db } from '@/db/postgre.js'; import { Meta } from '@/models/entities/meta.js'; @@ -17,9 +18,20 @@ export async function setMeta(meta: Meta): Promise { 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(); } +// 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. * If there is no entry yet, inserts a new one.