diff --git a/Console/Command/ProcessQueueCommand.php b/Console/Command/ProcessQueueCommand.php index 17004181..548b5332 100644 --- a/Console/Command/ProcessQueueCommand.php +++ b/Console/Command/ProcessQueueCommand.php @@ -18,12 +18,18 @@ class ProcessQueueCommand extends Command private $_queue; + private $_state; + + /** * @param State $state * @param Queue $queue */ public function __construct(State $state, Queue $queue) { + + $this->_state = $state; + $this->_queue = $queue; parent::__construct(); } @@ -45,7 +51,10 @@ protected function configure() */ protected function execute(InputInterface $input, OutputInterface $output) { - $success = $this->_queue->runNextJob(); + + $this->_state->setAreaCode(\Magento\Framework\App\Area::AREA_FRONTEND); + + $success = $this->_queue->process(); if ($success === true) { $output->writeln("Queue Processed."); } elseif ($success === false) { diff --git a/Cron/Process.php b/Cron/Process.php new file mode 100644 index 00000000..83802985 --- /dev/null +++ b/Cron/Process.php @@ -0,0 +1,43 @@ +<?php + +namespace Springbot\Queue\Cron; + +use Symfony\Component\Console\Command\Command; +use Symfony\Component\Console\Input\InputInterface; +use Symfony\Component\Console\Output\OutputInterface; +use Magento\Framework\App\State; +use Springbot\Queue\Model\Queue; + +/** + * Class ProcessQueueCommand + * + * @package Springbot\Queue\Console\Command + */ +class Process +{ + + private $_queue; + private $_state; + + /** + * @param State $state + * @param Queue $queue + */ + public function __construct(State $state, Queue $queue) + { + $this->_state = $state; + $this->_queue = $queue; + } + + /** + * @param InputInterface $input + * @param OutputInterface $output + * + * @return string + */ + public function execute() + { + //$this->_state->setAreaCode(\Magento\Framework\App\Area::AREA_FRONTEND); + $success = $this->_queue->process(); + } +} diff --git a/Model/Queue.php b/Model/Queue.php index 798665af..487b6746 100644 --- a/Model/Queue.php +++ b/Model/Queue.php @@ -178,14 +178,10 @@ public function runNextJob() public function process() { $maxJobs = $this->scopeConfig->getValue('springbot/queue/max_jobs'); - if (!is_numeric($maxJobs)) { - $maxJobs = 1; - } + $maxJobs=500; for ($i = 1; $i <= $maxJobs; $i++) { - if ($this->runNextJob() === null) { - return null; - } + $this->runNextJob(); } return true; } diff --git a/etc/config.xml b/etc/config.xml index f702822c..c8899796 100644 --- a/etc/config.xml +++ b/etc/config.xml @@ -5,7 +5,7 @@ <default> <springbot> <queue> - <max_jobs>1</max_jobs> + <max_jobs>100</max_jobs> </queue> </springbot> </default> diff --git a/etc/crontab.xml b/etc/crontab.xml new file mode 100644 index 00000000..c6e87520 --- /dev/null +++ b/etc/crontab.xml @@ -0,0 +1,9 @@ +<?xml version="1.0" ?> +<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Cron:etc/crontab.xsd"> + <group id="default"> + <job instance="Springbot\Queue\Cron\Process" method="execute" name="springbot_queue_process"> + <schedule>*/5 * * * *</schedule> + </job> + </group> +</config> +