Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save doried-a-a/4d4d5bcd34c290201eae316ccca8ba1f to your computer and use it in GitHub Desktop.
Save doried-a-a/4d4d5bcd34c290201eae316ccca8ba1f to your computer and use it in GitHub Desktop.
<?php
namespace AppBundle\MessageHandlers;
use whatever\ImagesBundle\Messages\ImageFilterAppliedMessage;
use Predis\Client;
use Symfony\Component\Messenger\Handler\MessageHandlerInterface;
class ImageFilterAppliedMessageHandler implements MessageHandlerInterface
{
const DAY_IN_SECONDS = 24*60*60;
private $imageCacheRedisClient;
public function __construct(Client $imageCacheRedisClient)
{
$this->imageCacheRedisClient = $imageCacheRedisClient;
}
public function __invoke(ImageFilterAppliedMessage $message)
{
list($isStored, $imgContent) = $this->imageCacheRedisClient->mget([$message->getRedisKey()."_stored", $message->getRedisKey()."_content"]);
$imgContent = $imgContent? base64_decode($imgContent) : false;
if($imgContent){
try{
# TODO please store the image to your specific cloud storage, in the same path that you put in line 48 of CacheResolver.php instead of $this->mountManager->getWebUrl
# This is a dump code, I used to have a mount manager that's configured to store the image in the right place
if ($this->mountManager->put($message->getImagePath(), $imgContent)) {
$this->imageCacheRedisClient->set($message->getRedisKey() . "_stored", true);
$this->imageCacheRedisClient->expire($message->getRedisKey()."_content", 60);
$this->imageCacheRedisClient->set(
$message->getRedisKey() . "_redirect",
$this->mountManager->getWebUrl($message->getImagePath()),
'EX',
10*self::DAY_IN_SECONDS
);
}
printf("Handled ImageFilterAppliesMessage %s ans stored image to %s\n", $message->getRedisKey(), $message->getImagePath());
}
catch (\Throwable $ee){
error_log($ee->getMessage());
throw $ee;
}
}
else {
printf("Could not find image content for message %s and images %s\n", $message->getRedisKey(), $message->getImagePath());
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment