Something went wrong. Try again.
Mirror — see github.com/blacksky-algorithms/blacksky.community
Something went wrong. Try again.
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849import cluster, {type Worker} from 'node:cluster'
import {envInt} from '@atproto/common'
import {CardService, envToCfg, httpLogger, readEnv} from './index.js'
async function main() { const env = readEnv() const cfg = envToCfg(env) const card = await CardService.create(cfg) await card.start() httpLogger.info('card service is running') process.on('SIGTERM', async () => { httpLogger.info('card service is stopping') await card.destroy() httpLogger.info('card service is stopped') if (cluster.isWorker) process.exit(0) })}
const workerCount = envInt('CARD_CLUSTER_WORKER_COUNT')
if (workerCount) { if (cluster.isPrimary) { httpLogger.info(`primary ${process.pid} is running`) const workers = new Set<Worker>() for (let i = 0; i < workerCount; ++i) { workers.add(cluster.fork()) } let teardown = false cluster.on('exit', worker => { workers.delete(worker) if (!teardown) { workers.add(cluster.fork()) // restart on crash } }) process.on('SIGTERM', () => { teardown = true httpLogger.info('disconnecting workers') workers.forEach(w => w.kill('SIGTERM')) }) } else { httpLogger.info(`worker ${process.pid} is running`) main() }} else { main() // non-clustering}