Skip to content

Commit

Permalink
Merge 0c785ca into 07d7ded
Browse files Browse the repository at this point in the history
  • Loading branch information
makasim authored Apr 28, 2017
2 parents 07d7ded + 0c785ca commit 8986975
Show file tree
Hide file tree
Showing 6 changed files with 109 additions and 1 deletion.
80 changes: 80 additions & 0 deletions Async/ResolveAllCacheProcessor.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
<?php
namespace Liip\ImagineBundle\Async;

use Enqueue\Client\TopicSubscriberInterface;
use Enqueue\Consumption\QueueSubscriberInterface;
use Enqueue\Psr\PsrContext;
use Enqueue\Psr\PsrMessage;
use Enqueue\Psr\PsrProcessor;
use Liip\ImagineBundle\Imagine\Cache\CacheManager;
use Liip\ImagineBundle\Imagine\Data\DataManager;
use Liip\ImagineBundle\Imagine\Filter\FilterManager;

class ResolveAllCacheProcessor implements PsrProcessor, TopicSubscriberInterface, QueueSubscriberInterface
{
/**
* @var CacheManager
*/
private $cacheManager;

/**
* @var FilterManager
*/
private $filterManager;

/**
* @var DataManager
*/
private $dataManager;
/**
* @param CacheManager $cacheManager
* @param FilterManager $filterManager
* @param DataManager $dataManager
*/
public function __construct(CacheManager $cacheManager, FilterManager $filterManager, DataManager $dataManager)
{
$this->cacheManager = $cacheManager;
$this->filterManager = $filterManager;
$this->dataManager = $dataManager;
}

/**
* {@inheritdoc}
*/
public function process(PsrMessage $psrMessage, PsrContext $psrContext)
{
$path = $psrMessage->getBody();
foreach ($this->filterManager->getFilterConfiguration()->all() as $filter => $config) {
if (false == $this->cacheManager->isStored($path, $filter)) {
$binary = $this->dataManager->find($filter, $path);
$this->cacheManager->store(
$this->filterManager->applyFilter($binary, $filter),
$path,
$filter
);
}

$this->cacheManager->resolve($path, $filter);
}

return self::ACK;
}

/**
* {@inheritdoc}
*/
public static function getSubscribedTopics()
{
return [
Topics::RESOLVE_ALL_CACHE => ['queueName' => Topics::RESOLVE_ALL_CACHE, 'queueNameHardcoded' => true]
];
}

/**
* {@inheritdoc}
*/
public static function getSubscribedQueues()
{
return [Topics::RESOLVE_ALL_CACHE];
}
}
7 changes: 7 additions & 0 deletions Async/Topics.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?php
namespace Liip\ImagineBundle\Async;

class Topics
{
const RESOLVE_ALL_CACHE = 'liip_imagine_resolve_all_cache';
}
1 change: 1 addition & 0 deletions DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,7 @@ public function getConfigTreeBuilder()
->end()
->end()
->end()
->booleanNode('enqueue')->defaultFalse()->info('Enables integration with enqueue if set true. Allows resolve image caches in background by sending messages to MQ.')->end()
->end();

return $treeBuilder;
Expand Down
4 changes: 4 additions & 0 deletions DependencyInjection/LiipImagineExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,10 @@ public function load(array $configs, ContainerBuilder $container)
$loader = new XmlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));
$loader->load('imagine.xml');

if ($config['enqueue']) {
$loader->load('enqueue.xml');
}

$this->setFactories($container);

if (interface_exists('Imagine\Image\Metadata\MetadataReaderInterface')) {
Expand Down
15 changes: 15 additions & 0 deletions Resources/config/enqueue.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?xml version="1.0" encoding="utf-8" ?>
<container xmlns="http://symfony.com/schema/dic/services"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd">

<services>
<service id="liip_imagine.async.resolve_all_cache_processor" class="Liip\ImagineBundle\Async\ResolveAllCacheProcessor">
<argument type="service" id="liip_imagine.cache.manager" />
<argument type="service" id="liip_imagine.filter.manager" />
<argument type="service" id="liip_imagine.data.manager" />

<tag name="enqueue.client.processor" />
</service>
</services>
</container>
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,8 @@
"doctrine/mongodb-odm": "required to use mongodb-backed doctrine components",
"league/flysystem": "required to use FlySystem data loader or cache resolver",
"monolog/monolog": "A psr/log compatible logger is required to enable logging",
"twig/twig": "required to use the provided Twig extension. Version 1.12 or greater needed"
"twig/twig": "required to use the provided Twig extension. Version 1.12 or greater needed",
"enqueue/enqueue-bundle": "required to warmup caches via message queues"
},
"minimum-stability": "dev",
"config": {
Expand Down

0 comments on commit 8986975

Please sign in to comment.