Skip to content

Add a cronjob to allow simple processing #9

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 10 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion Console/Command/ProcessQueueCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand All @@ -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) {
Expand Down
43 changes: 43 additions & 0 deletions Cron/Process.php
Original file line number Diff line number Diff line change
@@ -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();
}
}
8 changes: 2 additions & 6 deletions Model/Queue.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
2 changes: 1 addition & 1 deletion etc/config.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<default>
<springbot>
<queue>
<max_jobs>1</max_jobs>
<max_jobs>100</max_jobs>
</queue>
</springbot>
</default>
Expand Down
9 changes: 9 additions & 0 deletions etc/crontab.xml
Original file line number Diff line number Diff line change
@@ -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>