| 1234567891011121314151617181920212223242526272829303132333435 |
- const config = require('../config.json')
- const VALID_ROLES = new Set(['all', 'api', 'worker'])
- /**
- * 进程角色:all=API+乐跑Worker一体;api=仅HTTP入队;worker=仅消费乐跑任务
- * 环境变量 RUNFORGE_SERVER_ROLE 优先于 config.serverRole
- */
- function resolveServerRole() {
- const raw = process.env.RUNFORGE_SERVER_ROLE || config.serverRole || 'all'
- const role = String(raw).toLowerCase()
- if (VALID_ROLES.has(role)) return role
- console.warn(`[serverRole] 未知值 "${raw}",回退为 all`)
- return 'all'
- }
- function shouldServeApi(role) {
- return role === 'all' || role === 'api'
- }
- function shouldRunLepaoWorker(role) {
- return role === 'all' || role === 'worker'
- }
- /** 订单支付 MQ 消费者仅在 all 进程运行;api 只入队不消费 */
- function shouldRunOrderPaymentWorker(role) {
- return role === 'all'
- }
- module.exports = {
- resolveServerRole,
- shouldServeApi,
- shouldRunLepaoWorker,
- shouldRunOrderPaymentWorker
- }
|