我正在使用 Symfony 4.2 版。我使用我在下面写的其他包。
"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": "*"
我正在使用主管运行 cosume 命令。我在下面写了我的主管设置。
[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
实体管理器工作一段时间后关闭。我想我需要重新开始。但我无法在代码中做到这一点。但是当主管重新启动时,一切都开始工作了。我该如何解决这个问题,因为我不能总是从一开始就重新启动主管。
我正在编写下面的示例过程。
<?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'];
}
}