ZF2,Oracle,SlmQueueDoctrine,ClearObjectManagerStrategy不起作用
我有一个ZF2项目,具有以下配置。 它使用Doctrine ORM和SlmQueue。 由于SlmQueue不支持我们的命名约定和oracle数据库,因此我们定制了SlmQueueDoctrine。
我怀疑我的工作没有使用ClearObjectManagerStrategy,并且在执行单个作业之前没有清除ObjectManager。
它不反映队列启动后的数据库修改。 但是如果我终止队列守护进程并重新启动,它会选择新的值。
在执行单个作业之前,如何实现ClearObjectManagerStrategy并清除ObjectManager?
我已经尝试了许多没有运气的接近。
composer.json
{
"repositories": [
{
"url": "https://github.com/pradeep-sanjaya/doctrine-extensions.git",
"type": "git"
}
],
"require": {
"php": ">=5.3.3",
"zendframework/zendframework": "2.3.3",
"doctrine/doctrine-orm-module": "0.7.*",
"pradeep-sanjaya/doctrine-extensions": "dev-master",
"spoonx/sxmail": "1.4.*",
"slm/locale": "dev-master",
"imagine/Imagine": "0.6.*",
"tecnick.com/tcpdf": "dev-master",
"slm/queue": "0.4.*",
"slm/queue-doctrine": "0.4.*"
}
}
配置/自动加载/ slm_queue.local.php
<?php
return array(
'slm_queue' => array(
'queue_manager' => array(
'factories' => array(
'doctrineQueue' => 'SlmQueueDoctrineFactoryDoctrineQueueFactory'
),
),
'job_manager' => array(
'factories' => array(
'ReportJobRank' => 'ReportJobRankFactory',
),
'shared' => array(
'ReportJobRank' => false
),
),
'queues' => array(
'doctrineQueue' => array(
'table_name' => 'IOQUEUE'
)
)
)
);
?>
模块/报告/ src目录/报告/招聘/ Rank.php
<?php
namespace ReportJob;
use DoctrineModulePersistenceObjectManagerAwareInterface;
use DoctrineModulePersistenceProvidesObjectManager as ProvidesObjectManagerTrait;
use SlmQueueJobAbstractJob;
use ApplicationEntityReport;
use ApplicationLogLoggerAwareInterface;
use ApplicationLogLoggerAwareTrait;
use ApplicationServiceReportService;
class Rank extends AbstractJob implements ObjectManagerAwareInterface, LoggerAwareInterface
{
use LoggerAwareTrait;
use ProvidesObjectManagerTrait;
/**
* @var ReportService
*/
protected $reportService;
/**
* @var array
*/
protected $reportId = array();
public function setReportService(ReportService $reportService)
{
$this->reportService = $reportService;
}
/**
* Execute the job
*
* @return void
*/
public function execute()
{
//clear object manager does not work
//$om = $this->getObjectManager();
//$om->clear();
$content = $this->getContent();
$this->setReportId($content['reportId']);
if (!empty($this->reportId)) {
try {
if (is_array($this->reportId)) {
foreach ($this->reportId as $reportId) {
$this->updateRank($reportId);
}
unset($reportId);
} else {
$this->updateRank($this->reportId);
}
} catch (Exception $exception) {
echo "Exception message is {$exception->getMessage()} n";
}
}
}
private function updateRank($reportId)
{
/* @var $report Report */
$report = $this->reportService->getReport($reportId);
$this->logInfo(print_r($report, true)); // this always return older db values, the values before it start queue deamon
if (!$report instanceof Report) {
return;
}
if (empty($rankData)) {
return;
}
//more codes, application related logics
$this->reportService->updateReportEntity($report);
}
private function setReportId($reportId)
{
if (is_numeric($reportId)) {
$this->reportId = array($reportId);
} elseif (is_array($reportId)) {
$this->reportId = $reportId;
} else {
throw new Exception('Expects reportId as int or array');
}
}
}
如果你的意思是说它不完全清楚,那么显然这不是一个错误,而是预期的行为。
你可以查看文档章节7.5。 对于调用clear
方法的行为:
当调用EntityManager#clear()时,当前由EntityManager实例管理的所有实体都将分离。
在你的评论中你说过“它不会刷新对象管理器和当前事务”。 这不是您可以通过调用clear来执行的操作。 根据文档,分离会导致以下操作:
应用于实体X的分离操作的语义如下:
上一篇: ZF2, Oracle, SlmQueueDoctrine, ClearObjectManagerStrategy is not working
下一篇: Is critical SonarLint issue S1166 in my Java code a false positive or not?