14 use Psr\Log\LoggerInterface;
    15 use Symfony\Component\Process\PhpExecutableFinder;
    33     private $shellBackground;
    40     private $consumerConfig;
    47     private $deploymentConfig;
    54     private $phpExecutableFinder;
    61     private $pidConsumerManager;
    66     private $mqConnectionTypeResolver;
    84         PhpExecutableFinder $phpExecutableFinder,
    85         ConsumerConfigInterface $consumerConfig,
    90         LoggerInterface $logger = 
null    92         $this->phpExecutableFinder = $phpExecutableFinder;
    93         $this->consumerConfig = $consumerConfig;
    95         $this->shellBackground = $shellBackground;
    96         $this->pidConsumerManager = $pidConsumerManager;
    97         $this->mqConnectionTypeResolver = $mqConnectionTypeResolver
    99         $this->logger = $logger
   108         $runByCron = $this->deploymentConfig->get(
'cron_consumers_runner/cron_run', 
true);
   114         $maxMessages = (int) $this->deploymentConfig->get(
'cron_consumers_runner/max_messages', 10000);
   115         $allowedConsumers = $this->deploymentConfig->get(
'cron_consumers_runner/consumers', []);
   116         $php = $this->phpExecutableFinder->find() ?: 
'php';
   118         foreach ($this->consumerConfig->getConsumers() as $consumer) {
   119             if (!$this->canBeRun($consumer, $allowedConsumers)) {
   123             $consumerName = $consumer->getName();
   127                 '--pid-file-path=' . $this->getPidFilePath($consumerName),
   131                 $arguments[] = 
'--max-messages=' . $maxMessages;
   134             $command = $php . 
' ' . 
BP . 
'/bin/magento queue:consumers:start %s %s'   135                 . ($maxMessages ? 
' %s' : 
'');
   137             $this->shellBackground->execute($command, 
$arguments);
   152         $consumerName = $consumerConfig->
getName();
   153         if (!empty($allowedConsumers) && !in_array($consumerName, $allowedConsumers)) {
   157         if ($this->pidConsumerManager->isRun($this->getPidFilePath($consumerName))) {
   163             $this->mqConnectionTypeResolver->getConnectionType($connectionName);
   164         } 
catch (\LogicException $e) {
   165             $this->logger->info(sprintf(
   166                 'Consumer "%s" skipped as required connection "%s" is not configured. %s',
   183     private function getPidFilePath($consumerName)
   185         $sanitizedHostname = preg_replace(
'/[^a-z0-9]/i', 
'', 
gethostname());
   187         return $consumerName . 
'-' . $sanitizedHostname . static::PID_FILE_EXT;
 
__construct(PhpExecutableFinder $phpExecutableFinder, ConsumerConfigInterface $consumerConfig, DeploymentConfig $deploymentConfig, ShellInterface $shellBackground, PidConsumerManager $pidConsumerManager, ConnectionTypeResolver $mqConnectionTypeResolver=null, LoggerInterface $logger=null)