Skip to content

Commit

Permalink
add tests, add on success message, add force
Browse files Browse the repository at this point in the history
  • Loading branch information
makasim committed May 3, 2017
1 parent 0c785ca commit b6811dd
Show file tree
Hide file tree
Showing 5 changed files with 387 additions and 5 deletions.
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ before_install:
- if [ "${TRAVIS_PHP_VERSION}" != "hhvm" ] && [ "${TRAVIS_PHP_VERSION:0:3}" != "5.3" ]; then composer require --no-update --dev league/flysystem:~1.0; fi;
- if [ "${TRAVIS_PHP_VERSION}" != "hhvm" ] && [ "${TRAVIS_PHP_VERSION:0:1}" != "7" ]; then yes "" | pecl -q install -f mongo; composer require --no-update --dev doctrine/mongodb-odm:~1.0; fi;
- if [ "${TRAVIS_PHP_VERSION}" != "hhvm" ] && [ "${TRAVIS_PHP_VERSION:0:1}" == "7" ]; then yes "" | pecl -q install -f mongodb; travis_retry composer require --dev alcaeus/mongo-php-adapter:~1.0; composer require --no-update --dev doctrine/mongodb-odm:~1.0; fi
- if [ "${TRAVIS_PHP_VERSION}" != "hhvm" ] && [ "${TRAVIS_PHP_VERSION:0:3}" -ge "5.6" ]; then composer require --no-update --dev enqueue/enqueue-bundle:^0.3.6; fi;

install:
- travis_retry composer update $COMPOSER_FLAGS
Expand Down
45 changes: 41 additions & 4 deletions Async/ResolveAllCacheProcessor.php
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
<?php
namespace Liip\ImagineBundle\Async;

use Enqueue\Client\ProducerInterface;
use Enqueue\Client\TopicSubscriberInterface;
use Enqueue\Consumption\QueueSubscriberInterface;
use Enqueue\Consumption\Result;
use Enqueue\Psr\PsrContext;
use Enqueue\Psr\PsrMessage;
use Enqueue\Psr\PsrProcessor;
use Enqueue\Util\JSON;
use Liip\ImagineBundle\Imagine\Cache\CacheManager;
use Liip\ImagineBundle\Imagine\Data\DataManager;
use Liip\ImagineBundle\Imagine\Filter\FilterManager;
Expand All @@ -26,25 +29,54 @@ class ResolveAllCacheProcessor implements PsrProcessor, TopicSubscriberInterface
* @var DataManager
*/
private $dataManager;

/**
* @var ProducerInterface
*/
private $producer;

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

/**
* {@inheritdoc}
*/
public function process(PsrMessage $psrMessage, PsrContext $psrContext)
{
$path = $psrMessage->getBody();
try {
$body = JSON::decode($psrMessage->getBody());
} catch (\Exception $e) {
return Result::reject($e->getMessage());
}

$body = array_replace(['path' => null, 'force' => false], $body);

if (false == $body['path']) {
return Result::reject('The message does not contain "path" but it is required.');
}

$path = $body['path'];
$results = [];
foreach ($this->filterManager->getFilterConfiguration()->all() as $filter => $config) {
if ($this->cacheManager->isStored($path, $filter) && $body['force']) {
$this->cacheManager->remove($path, $filter);
}

if (false == $this->cacheManager->isStored($path, $filter)) {
$binary = $this->dataManager->find($filter, $path);
$this->cacheManager->store(
Expand All @@ -54,9 +86,14 @@ public function process(PsrMessage $psrMessage, PsrContext $psrContext)
);
}

$this->cacheManager->resolve($path, $filter);
$results[$filter] = $this->cacheManager->resolve($path, $filter);
}

$this->producer->send(Topics::ALL_CACHE_RESOLVED, [
'path' => $path,
'filters' => $results,
]);

return self::ACK;
}

Expand Down
2 changes: 2 additions & 0 deletions Async/Topics.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,6 @@
class Topics
{
const RESOLVE_ALL_CACHE = 'liip_imagine_resolve_all_cache';

const ALL_CACHE_RESOLVED = 'liip_imagine_all_cache_resolve_d';
}
Loading

0 comments on commit b6811dd

Please sign in to comment.