forked from liip/LiipImagineBundle
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathResolveCacheProcessor.php
More file actions
101 lines (86 loc) · 2.88 KB
/
ResolveCacheProcessor.php
File metadata and controls
101 lines (86 loc) · 2.88 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
<?php
/*
* This file is part of the `liip/LiipImagineBundle` project.
*
* (c) https://github.com/liip/LiipImagineBundle/graphs/contributors
*
* For the full copyright and license information, please view the LICENSE.md
* file that was distributed with this source code.
*/
namespace Liip\ImagineBundle\Async;
use Enqueue\Client\CommandSubscriberInterface;
use Enqueue\Client\ProducerInterface;
use Enqueue\Consumption\QueueSubscriberInterface;
use Enqueue\Consumption\Result;
use Enqueue\Util\JSON;
use Interop\Queue\Context;
use Interop\Queue\Message;
use Interop\Queue\Processor;
use Liip\ImagineBundle\Imagine\Filter\FilterManager;
use Liip\ImagineBundle\Service\FilterService;
/**
* @deprecated Use Liip\ImagineBundle\Message\Handler\WarmupCacheHandler instead
*/
final class ResolveCacheProcessor implements Processor, CommandSubscriberInterface, QueueSubscriberInterface
{
/**
* @var FilterManager
*/
private $filterManager;
/**
* @var FilterService
*/
private $filterService;
/**
* @var ProducerInterface
*/
private $producer;
public function __construct(
FilterManager $filterManager,
FilterService $filterService,
ProducerInterface $producer
) {
$this->filterManager = $filterManager;
$this->filterService = $filterService;
$this->producer = $producer;
}
/**
* @return string|object
*/
public function process(Message $psrMessage, Context $psrContext)
{
try {
$message = ResolveCache::jsonDeserialize($psrMessage->getBody());
$filters = $message->getFilters() ?: array_keys($this->filterManager->getFilterConfiguration()->all());
$path = $message->getPath();
$results = [];
foreach ($filters as $filter) {
$this->filterService->warmUpCache($path, $filter, null, $message->isForce());
$results[$filter] = $this->filterService->getUrlOfFilteredImage($path, $filter);
}
$this->producer->sendEvent(Topics::CACHE_RESOLVED, new CacheResolved($path, $results));
return Result::reply($psrContext->createMessage(JSON::encode([
'status' => true,
'results' => $results,
])));
} catch (\Exception $e) {
return Result::reply($psrContext->createMessage(JSON::encode([
'status' => false,
'exception' => $e->getMessage(),
])), Result::REJECT, $e->getMessage());
}
}
public static function getSubscribedCommand(): array
{
return [
'command' => Commands::RESOLVE_CACHE,
'queue' => Commands::RESOLVE_CACHE,
'prefix_queue' => false,
'exclusive' => true,
];
}
public static function getSubscribedQueues(): array
{
return [Commands::RESOLVE_CACHE];
}
}