I am using Symfony version 4.2 . I use other packages I write below.
"php": "^7.1.3",
"ext-ctype": "*",
"ext-iconv": "*",
"enqueue/enqueue-bundle": "^0.9.7",
"enqueue/pheanstalk": "^0.9.7",
"friendsofsymfony/elastica-bundle": "^5.0",
"nelmio/cors-bundle": "^1.5",
"nesbot/carbon": "^2.10",
"symfony/console": "*",
"symfony/flex": "^1.1",
"symfony/framework-bundle": "*",
"symfony/orm-pack": "^1.0",
"symfony/serializer-pack": "^1.0",
"symfony/yaml": "*"
I am running the cosume command using a supervisor. I write my supervisor setting below.
[program:devlog-worker]
process_name=%(program_name)s_%(process_num)02d
command=php /var/www/project-directory/bin/console enqueue:consume --setup-broker
autostart=true
autorestart=true
user=nginx
numprocs=1
redirect_stderr=true
stdout_logfile=/var/www/project-directory/worker.log
Entity manager is closed after working for a certain period of time. I think I need to start again. But I could not do it in the code. But when the supervisor restarts, everything starts working. How can I solve this problem because I cant always restart supervisor from the beginning.
I'm writing the sample process below.
<?php
namespace App\Processor;
use App\Entity\Main\Event;
use Doctrine\ORM\EntityManagerInterface;
use Interop\Queue\Message;
use Interop\Queue\Context;
use Interop\Queue\Processor;
use Enqueue\Client\TopicSubscriberInterface;
class FooProcessor implements Processor, TopicSubscriberInterface
{
protected $entityManager;
public function __construct(EntityManagerInterface $entityManager)
{
$this->entityManager = $entityManager;
}
public function process(Message $message, Context $session)
{
try {
$event = new Event();
$event->setAction('example');
if (!$this->entityManager->isOpen()) {
echo "Entity Manger is closed...\n";
// here i need to restart the entity manager or another solution
}
$this->entityManager->persist($event);
$this->entityManager->flush();
$this->entityManager->clear();
echo "Success\n";
return self::ACK;
} catch (\Exception $e){
echo ($e->getMessage())." \n";
return self::REJECT;
}
}
public static function getSubscribedTopics()
{
return ['aFooTopic'];
}
}