Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Public Member Functions | Data Fields
ConsumersRunner Class Reference

Public Member Functions

 __construct (PhpExecutableFinder $phpExecutableFinder, ConsumerConfigInterface $consumerConfig, DeploymentConfig $deploymentConfig, ShellInterface $shellBackground, PidConsumerManager $pidConsumerManager, ConnectionTypeResolver $mqConnectionTypeResolver=null, LoggerInterface $logger=null)
 
 run ()
 

Data Fields

const PID_FILE_EXT = '.pid'
 

Detailed Description

Class for running consumers processes by cron

Definition at line 21 of file ConsumersRunner.php.

Constructor & Destructor Documentation

◆ __construct()

__construct ( PhpExecutableFinder  $phpExecutableFinder,
ConsumerConfigInterface  $consumerConfig,
DeploymentConfig  $deploymentConfig,
ShellInterface  $shellBackground,
PidConsumerManager  $pidConsumerManager,
ConnectionTypeResolver  $mqConnectionTypeResolver = null,
LoggerInterface  $logger = null 
)
Parameters
PhpExecutableFinder$phpExecutableFinderThe executable finder specifically designed for the PHP executable
ConsumerConfigInterface$consumerConfigThe consumer config provider
DeploymentConfig$deploymentConfigThe application deployment configuration
ShellInterface$shellBackgroundThe shell command line wrapper for executing command in background
PidConsumerManager$pidConsumerManagerThe class for checking status of process by PID
ConnectionTypeResolver$mqConnectionTypeResolverConsumer connection resolver
LoggerInterface$loggerLogger

Definition at line 83 of file ConsumersRunner.php.

91  {
92  $this->phpExecutableFinder = $phpExecutableFinder;
93  $this->consumerConfig = $consumerConfig;
94  $this->deploymentConfig = $deploymentConfig;
95  $this->shellBackground = $shellBackground;
96  $this->pidConsumerManager = $pidConsumerManager;
97  $this->mqConnectionTypeResolver = $mqConnectionTypeResolver
98  ?: ObjectManager::getInstance()->get(ConnectionTypeResolver::class);
99  $this->logger = $logger
100  ?: ObjectManager::getInstance()->get(LoggerInterface::class);
101  }
$logger
$deploymentConfig

Member Function Documentation

◆ run()

run ( )

Runs consumers processes

Definition at line 106 of file ConsumersRunner.php.

107  {
108  $runByCron = $this->deploymentConfig->get('cron_consumers_runner/cron_run', true);
109 
110  if (!$runByCron) {
111  return;
112  }
113 
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';
117 
118  foreach ($this->consumerConfig->getConsumers() as $consumer) {
119  if (!$this->canBeRun($consumer, $allowedConsumers)) {
120  continue;
121  }
122 
123  $consumerName = $consumer->getName();
124 
125  $arguments = [
126  $consumerName,
127  '--pid-file-path=' . $this->getPidFilePath($consumerName),
128  ];
129 
130  if ($maxMessages) {
131  $arguments[] = '--max-messages=' . $maxMessages;
132  }
133 
134  $command = $php . ' ' . BP . '/bin/magento queue:consumers:start %s %s'
135  . ($maxMessages ? ' %s' : '');
136 
137  $this->shellBackground->execute($command, $arguments);
138  }
139  }
$arguments
const BP
Definition: autoload.php:14

Field Documentation

◆ PID_FILE_EXT

const PID_FILE_EXT = '.pid'

Extension of PID file

Definition at line 26 of file ConsumersRunner.php.


The documentation for this class was generated from the following file: