Skip to content

Commit

Permalink
Merge 0b067ee into f102cac
Browse files Browse the repository at this point in the history
  • Loading branch information
TiSiE committed Feb 8, 2019
2 parents f102cac + 0b067ee commit 57fe22c
Show file tree
Hide file tree
Showing 35 changed files with 3,002 additions and 4 deletions.
1 change: 0 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ matrix:
env: COVERAGE=yes
- php: 7.3
include:
- php: 5.6
- php: 7.1
- php: 7.2
- php: 7.3
Expand Down
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
"minimum-stability": "dev",
"prefer-stable": true,
"require": {
"php": ">=5.6",
"php": ">=7.1",
"ext-intl": "*",
"ext-mongodb": "*",
"alcaeus/mongo-php-adapter": "^1.0.0",
Expand All @@ -45,6 +45,7 @@
"jmikola/geojson": "^1.0",
"mpdf/mpdf": "5.7.*",
"sebastian/version": "^2.0",
"slm/queue": "^1.0",
"symfony/console": "^3.4 | ^4.1",
"symfony/dotenv": "^3.4 | ^4.1",
"symfony/filesystem": "^3.4 | ^4.1",
Expand Down
3 changes: 2 additions & 1 deletion module/Core/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
"yawik", "module", "zf3"
],
"require": {
"php": ">=5.6",
"php": ">=7.1",
"ext-intl": "*",
"ext-mongodb": "*",
"alcaeus/mongo-php-adapter": "^1.0.0",
Expand All @@ -34,6 +34,7 @@
"symfony/finder": "^3.4 | ^4.1",
"symfony/process": "^3.4 | ^4.1",
"tracy/tracy": "^2.4",
"slm/queue": "^1.0",
"zendframework/zend-authentication": "^2.5",
"zendframework/zend-cache": "^2.7",
"zendframework/zend-captcha": "^2.7",
Expand Down
79 changes: 78 additions & 1 deletion module/Core/config/module.config.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,37 @@

'doctrine' => $doctrineConfig,

'slm_queue' => [
'worker_strategies' => [
'default' => [
Queue\Strategy\IdleSleepStrategy::class => ['duration' => 1],
],
'queues' => [
'default' => [
Queue\Strategy\LogStrategy::class => ['log' => 'Log/Core/Queue'],
],
],
],
'strategy_manager' => [
'factories' => [
Queue\Strategy\LogStrategy::class => Queue\Strategy\LogStrategyFactory::class,
],
],
'queue_manager' => [
'factories' => [
'default' => Queue\MongoQueueFactory::class,
],
],
'job_manager' => [
'aliases' => [
'lazy' => Queue\LazyJob::class,
],
'factories' => [
Queue\LazyJob::class => Queue\LazyJobFactory::class,
]
]
],

'options' => [
'Core/MailServiceOptions' => [ 'class' => '\Core\Options\MailServiceOptions' ],
],
Expand Down Expand Up @@ -62,15 +93,40 @@
'options' => array(
'stream' => getcwd().'/var/log/mails.log',
),

),
),
),
'Log/Core/Queue' => array(
'writers' => array(
array(
'name' => 'stream',
'priority' => 1000,
'options' => array(
'stream' => getcwd().'/var/log/queue.log',
'formatter' => [
'name' => 'simple',
'options' => [
'format' => '%timestamp% (%pid%) %priorityName%: %message% %extra%',
'dateTimeFormat' => 'd.m.Y H:i:s',
],
],
),
),
),
'processors' => array(
array('name' => Log\Processor\ProcessId::class),
),
),
),

'log_processors' => [
'invokables' => [
'Core/UniqueId' => 'Core\Log\Processor\UniqueId',
],
'factories' => [
Log\Processor\ProcessId::class => \Zend\ServiceManager\Factory\InvokableFactory::class,
],
],

'tracy' => [
Expand Down Expand Up @@ -206,6 +262,24 @@
'action' => 'index',
]
]
],
'mongo-queue-list' => [
'options' => [
'route' => 'queue mongo --list <queue> [--limit=]',
'defaults' => [
'controller' => Queue\Controller\MongoQueueListController::class,
'action' => 'list',
],
],
],
'mongo-queue' => [
'options' => [
'route' => 'queue mongo <queue>',
'defaults' => [
'controller' => Queue\Controller\MongoQueueController::class,
'action' => 'process',
]
]
]
],
],
Expand Down Expand Up @@ -277,7 +351,8 @@
'Core/Listener/Notification' => [\Core\Listener\NotificationListener::class,'factory'],
'Tracy' => [Tracy::class,'factory'],
Service\EntityEraser\DefaultEntityLoaderListener::class => Service\EntityEraser\DefaultEntityLoaderListenerFactory::class,
ClearCacheService::class => [ClearCacheService::class,'factory']
ClearCacheService::class => [ClearCacheService::class,'factory'],
Queue\Worker\MongoWorker::class => \SlmQueue\Factory\WorkerFactory::class,
),
'abstract_factories' => array(
'Core\Factory\OptionsAbstractFactory',
Expand Down Expand Up @@ -347,6 +422,8 @@
Controller\Console\PurgeController::class => Controller\Console\PurgeControllerFactory::class,
AssetsInstallController::class => [AssetsInstallController::class,'factory'],
ClearCacheController::class => [ClearCacheController::class,'factory'],
Queue\Controller\MongoQueueController::class => Queue\Controller\MongoQueueControllerFactory::class,
Queue\Controller\MongoQueueListController::class => Queue\Controller\MongoQueueListControllerFactory::class,

],
),
Expand Down
35 changes: 35 additions & 0 deletions module/Core/src/Log/Processor/ProcessId.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?php
/**
* YAWIK
*
* @filesource
* @license MIT
* @copyright 2013 - 2016 Cross Solution <http://cross-solution.de>
*/

/** */
namespace Core\Log\Processor;

use Zend\Log\Processor\ProcessorInterface;

/**
* Adds the process id to the event array in the key 'pid'.
*
* @author Mathias Gelhausen <gelhausen@cross-solution.de>
*/
class ProcessId implements ProcessorInterface
{
/**
* Adds process id to the event array.
*
* @param array $event
*
* @return array
*/
public function process(array $event)
{
$event['pid'] = getmypid();

return $event;
}
}
23 changes: 23 additions & 0 deletions module/Core/src/Queue/Controller/MongoQueueController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?php
/**
* YAWIK
*
* @filesource
* @license MIT
* @copyright 2013 - 2019 Cross Solution <http://cross-solution.de>
*/

/** */
namespace Core\Queue\Controller;

use SlmQueue\Controller\AbstractWorkerController;

/**
* Console Controller for mongo queues
*
* @author Mathias Gelhausen <gelhausen@cross-solution.de>
*/
class MongoQueueController extends AbstractWorkerController
{

}
35 changes: 35 additions & 0 deletions module/Core/src/Queue/Controller/MongoQueueControllerFactory.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?php
/**
* YAWIK
*
* @filesource
* @license MIT
* @copyright 2013 - 2019 Cross Solution <http://cross-solution.de>
*/

/** */
namespace Core\Queue\Controller;

use Core\Queue\Worker\MongoWorker;
use Interop\Container\ContainerInterface;
use SlmQueue\Queue\QueuePluginManager;
use Zend\ServiceManager\Factory\FactoryInterface;

/**
* Factory for \Core\Queue\Controller\MongoQueueController
*
* @author Mathias Gelhausen <gelhausen@cross-solution.de>
*/
class MongoQueueControllerFactory implements FactoryInterface
{

public function __invoke(ContainerInterface $container, $requestedName, array $options = null)
{
$service = new MongoQueueController(
$container->get(MongoWorker::class),
$container->get(QueuePluginManager::class)
);

return $service;
}
}
90 changes: 90 additions & 0 deletions module/Core/src/Queue/Controller/MongoQueueListController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
<?php
/**
* YAWIK
*
* @filesource
* @license MIT
* @copyright 2013 - 2019 Cross Solution <http://cross-solution.de>
*/

/** */
namespace Core\Queue\Controller;

use Core\Queue\MongoQueue;
use SlmQueue\Queue\QueuePluginManager;
use Zend\Mvc\Console\Controller\AbstractConsoleController;

/**
* Console controller for list queue jobs.
*
* @author Mathias Gelhausen <gelhausen@cross-solution.de>
*/
class MongoQueueListController extends AbstractConsoleController
{
/**
* The queue plugin manager
*
* @var QueuePluginManager
*/
private $queuePluginManager;

/**
* MongoQueueListController constructor.
*
* @param QueuePluginManager $queuePluginManager
*/
public function __construct(QueuePluginManager $queuePluginManager)
{
$this->queuePluginManager = $queuePluginManager;
}

/**
* List jobs from a queue
*
* @return string
*/
public function listAction()
{
$queue = $this->params()->fromRoute('queue');
$queue = $this->queuePluginManager->get($queue);

if (!$queue instanceOf MongoQueue) {
return 'Unsupported queue type.';
}

$statusMap = function($stat) {
static $map = [
'pending' => MongoQueue::STATUS_PENDING,
'running' => MongoQueue::STATUS_RUNNING,
'failed' => MongoQueue::STATUS_FAILED,
];

return $map[$stat] ?? $map['pending'];
};

$console = $this->getConsole();
$jobs = $queue->listing([
'limit' => (int) $this->params()->fromRoute('limit', 0),
'status' => $statusMap($this->params()->fromRoute('status')),
]);

if (!$jobs) {
return 'Queue is empty.';
}

$lineTmpl = '%-20s %s';
foreach ($jobs as $job) {
$console->writeLine(get_class($job['job']) . ' [ ' . $job['job']->getId() . ' ]');

foreach (['created', 'executed', 'scheduled'] as $key) {
$console->writeLine(sprintf($lineTmpl, ucFirst($key), $job[$key]->toDateTime()->format('Y-m-d H:i:s')));
}
$console->writeLine(sprintf($lineTmpl, 'Tries', $job['tried']));
$console->writeLine();
$console->writeLine();
}

return '';
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?php
/**
* YAWIK
*
* @filesource
* @license MIT
* @copyright 2013 - 2019 Cross Solution <http://cross-solution.de>
*/

/** */
namespace Core\Queue\Controller;

use Interop\Container\ContainerInterface;
use SlmQueue\Queue\QueuePluginManager;
use Zend\ServiceManager\Factory\FactoryInterface;

/**
* Factory for \Core\Queue\Controller\MongoQueueListController
*
* @author Mathias Gelhausen <gelhausen@cross-solution.de>
* @todo write test
*/
class MongoQueueListControllerFactory implements FactoryInterface
{

public function __invoke(ContainerInterface $container, $requestedName, array $options = null)
{
$service = new MongoQueueListController(
$container->get(QueuePluginManager::class)
);

return $service;
}
}
Loading

0 comments on commit 57fe22c

Please sign in to comment.