import cluster from "cluster" ; import { getLogger } from "../../config/logger" ; import { ClusterCommand } from "./send-command" ; import { isNodeProd } from "../../util/isNodeEnv" ; const logger = getLogger ( "cluster.listen-command" ) ; export const listenForClusterCommand = ( command , callback ) => { if ( isNodeProd ( ) && ! cluster . isWorker ) { logger . debug ( "Only workers can listen for commands, skipping." ) ; return ; } logger . info ( { command } , `Listening for command "${ command }" on worker "${ cluster . worker . id }"` ) ; process . on ( "message" , msg => { logger . info ( { msg , command } , `Received message from master process on worker "${ cluster . worker . id }"` ) ; if ( msg === command ) { callback ( ) ; } } ) ; } ;