|
8 | 8 |
|
9 | 9 | import cluster from 'node:cluster' |
10 | 10 | import process from 'node:process' |
| 11 | +import { createTopicsIfNotExist } from '@badaitech/chaingraph-executor/server' |
11 | 12 | import { config } from './config' |
12 | 13 | import { logger } from './logger' |
13 | 14 | import { startMaster } from './master' |
14 | 15 | import { startWorker } from './worker' |
15 | 16 |
|
16 | 17 | // Determine if this is the master process or a worker |
17 | | -if (cluster.isPrimary) { |
18 | | - logger.info('🚀 Starting Chaingraph Execution Worker Service') |
19 | | - logger.info({ |
20 | | - masterPid: process.pid, |
21 | | - workers: config.workers.count, |
22 | | - mode: config.executionMode, |
23 | | - }, 'Service configuration') |
| 18 | +async function main() { |
| 19 | + if (cluster.isPrimary) { |
| 20 | + logger.info('🚀 Starting Chaingraph Execution Worker Service') |
| 21 | + logger.info({ |
| 22 | + masterPid: process.pid, |
| 23 | + workers: config.workers.count, |
| 24 | + mode: config.executionMode, |
| 25 | + }, 'Service configuration') |
24 | 26 |
|
25 | | - startMaster() |
26 | | -} else { |
27 | | - // This is a worker process |
28 | | - startWorker() |
| 27 | + // Create Kafka topics if in distributed mode |
| 28 | + if (config.executionMode === 'distributed') { |
| 29 | + logger.info('Creating Kafka topics if they don\'t exist') |
| 30 | + await createTopicsIfNotExist() |
| 31 | + } |
| 32 | + |
| 33 | + startMaster() |
| 34 | + } else { |
| 35 | + // This is a worker process |
| 36 | + await startWorker() |
| 37 | + } |
29 | 38 | } |
| 39 | + |
| 40 | +main().catch((error) => { |
| 41 | + logger.error({ error }, 'Failed to start service') |
| 42 | + process.exit(1) |
| 43 | +}) |
0 commit comments