Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
ConsumerRunner.php
Go to the documentation of this file.
1 <?php
7 
12 
26 {
30  private $consumerFactory;
31 
35  private $maintenanceMode;
36 
40  private $maintenanceSleepInterval;
41 
49  public function __construct(
50  ConsumerFactory $consumerFactory,
51  MaintenanceMode $maintenanceMode = null,
52  $maintenanceSleepInterval = 30
53  ) {
54  $this->consumerFactory = $consumerFactory;
55  $this->maintenanceMode = $maintenanceMode ?: ObjectManager::getInstance()->get(MaintenanceMode::class);
56  $this->maintenanceSleepInterval = $maintenanceSleepInterval;
57  }
58 
67  public function __call($name, $arguments)
68  {
69  try {
70  $consumer = $this->consumerFactory->get($name);
71  } catch (\Exception $e) {
72  $errorMsg = '"%callbackMethod" callback method specified in crontab.xml '
73  . 'must have corresponding consumer declared in some queue.xml.';
74  throw new LocalizedException(__($errorMsg, ['callbackMethod' => $name]));
75  }
76  if (!$this->maintenanceMode->isOn()) {
77  $consumer->process();
78  } else {
79  sleep($this->maintenanceSleepInterval);
80  }
81  }
82 }
__construct(ConsumerFactory $consumerFactory, MaintenanceMode $maintenanceMode=null, $maintenanceSleepInterval=30)
__()
Definition: __.php:13
$arguments
if(!isset($_GET['name'])) $name
Definition: log.php:14