relay filter/appview bootstrap
1import { logger } from '../util/logger'; 2 3const spawnOptions: { stdout: 'inherit' | 'pipe' | 'ignore', stderr: 'inherit' | 'pipe' | 'ignore' } = { 4 stdout: 'inherit', 5 stderr: 'inherit', 6}; 7 8const dir = import.meta.dir + '/..'; 9 10type Subprocess = ReturnType<typeof Bun.spawn>; 11 12let discoveryProcess: Subprocess | undefined; 13let backfillProcess: Subprocess | undefined; 14 15async function main() { 16 logger.info('Starting parallel backfill operations...'); 17 18 const backfillPath = `${dir}/pds/backfill.ts`; 19 backfillProcess = Bun.spawn(['bun', backfillPath], spawnOptions); 20 logger.info({ pid: backfillProcess.pid }, 'Backfill (Worker) process started'); 21 22 const discoveryPath = `${dir}/pds/discovery.ts`; 23 discoveryProcess = Bun.spawn(['bun', discoveryPath], spawnOptions); 24 logger.info({ pid: discoveryProcess.pid }, 'Discovery (PLC Sync) process started'); 25 26 if (discoveryProcess) { 27 await discoveryProcess.exited; 28 logger.info('Discovery process finished syncing.'); 29 logger.info('Backfill worker is still running to process the queue. Press Ctrl+C to stop.'); 30 } 31 32 if (backfillProcess) { 33 await backfillProcess.exited; 34 logger.warn('Backfill worker exited unexpectedly.'); 35 } 36} 37 38const cleanup = () => { 39 logger.info('\nStopping backfill subprocesses...'); 40 41 if (discoveryProcess && !discoveryProcess.killed) { 42 discoveryProcess.kill(); 43 logger.info('Killed discovery process'); 44 } 45 if (backfillProcess && !backfillProcess.killed) { 46 backfillProcess.kill('SIGTERM'); 47 logger.info('Signaled backfill process to stop (waiting for graceful exit)...'); 48 } 49 50 setTimeout(() => process.exit(0), 1000); 51}; 52 53process.on('SIGINT', cleanup); 54process.on('SIGTERM', cleanup); 55 56main();