mirror of
https://github.com/alchemy-fr/Phraseanet.git
synced 2025-10-23 09:53:15 +00:00
fix mysql server gone away and dead lock on table
This commit is contained in:
@@ -102,4 +102,12 @@ class WorkerRunningJobRepository extends EntityRepository
|
||||
{
|
||||
return parent::getEntityManager();
|
||||
}
|
||||
|
||||
public function reconnect()
|
||||
{
|
||||
if($this->_em->getConnection()->ping() === false) {
|
||||
$this->_em->getConnection()->close();
|
||||
$this->_em->getConnection()->connect();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -101,6 +101,9 @@ class RecordSubscriber implements EventSubscriberInterface
|
||||
|
||||
$repoWorker = $this->getRepoWorker();
|
||||
$em = $repoWorker->getEntityManager();
|
||||
// check connection an re-connect if needed
|
||||
$repoWorker->reconnect();
|
||||
|
||||
$workerRunningJob = $repoWorker->findOneBy([
|
||||
'databoxId' => $event->getRecord()->getDataboxId(),
|
||||
'recordId' => $event->getRecord()->getRecordId(),
|
||||
@@ -108,13 +111,15 @@ class RecordSubscriber implements EventSubscriberInterface
|
||||
'workOn' => $event->getSubdefName()
|
||||
]);
|
||||
|
||||
$em->beginTransaction();
|
||||
try {
|
||||
$em->remove($workerRunningJob);
|
||||
$em->flush();
|
||||
$em->commit();
|
||||
} catch (\Exception $e) {
|
||||
$em->rollback();
|
||||
if ($workerRunningJob) {
|
||||
$em->beginTransaction();
|
||||
try {
|
||||
$em->remove($workerRunningJob);
|
||||
$em->flush();
|
||||
$em->commit();
|
||||
} catch (\Exception $e) {
|
||||
$em->rollback();
|
||||
}
|
||||
}
|
||||
|
||||
$this->messagePublisher->publishMessage(
|
||||
@@ -223,6 +228,9 @@ class RecordSubscriber implements EventSubscriberInterface
|
||||
|
||||
$repoWorker = $this->getRepoWorker();
|
||||
$em = $repoWorker->getEntityManager();
|
||||
// check connection an re-connect if needed
|
||||
$repoWorker->reconnect();
|
||||
|
||||
$workerRunningJob = $repoWorker->findOneBy([
|
||||
'databoxId' => $event->getRecord()->getDataboxId(),
|
||||
'recordId' => $event->getRecord()->getRecordId(),
|
||||
@@ -230,13 +238,15 @@ class RecordSubscriber implements EventSubscriberInterface
|
||||
'workOn' => $event->getSubdefName()
|
||||
]);
|
||||
|
||||
$em->beginTransaction();
|
||||
try {
|
||||
$em->remove($workerRunningJob);
|
||||
$em->flush();
|
||||
$em->commit();
|
||||
} catch (\Exception $e) {
|
||||
$em->rollback();
|
||||
if ($workerRunningJob) {
|
||||
$em->beginTransaction();
|
||||
try {
|
||||
$em->remove($workerRunningJob);
|
||||
$em->flush();
|
||||
$em->commit();
|
||||
} catch (\Exception $e) {
|
||||
$em->rollback();
|
||||
}
|
||||
}
|
||||
|
||||
$this->messagePublisher->publishMessage(
|
||||
|
@@ -81,6 +81,7 @@ class SubdefCreationWorker implements WorkerInterface
|
||||
|
||||
// tell that a file is in used to create subdef
|
||||
$em = $this->repoWorker->getEntityManager();
|
||||
$this->repoWorker->reconnect();
|
||||
$em->beginTransaction();
|
||||
|
||||
try {
|
||||
@@ -108,13 +109,13 @@ class SubdefCreationWorker implements WorkerInterface
|
||||
try {
|
||||
$this->subdefGenerator->generateSubdefs($record, $wantedSubdef);
|
||||
} catch (\Exception $e) {
|
||||
$em->beginTransaction();
|
||||
try {
|
||||
$this->repoWorker->reconnect();
|
||||
$em->getConnection()->beginTransaction();
|
||||
$em->remove($workerRunningJob);
|
||||
$em->flush();
|
||||
$em->commit();
|
||||
} catch (\Exception $e) {
|
||||
$em->rollback();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -170,7 +171,8 @@ class SubdefCreationWorker implements WorkerInterface
|
||||
$this->indexer->flushQueue();
|
||||
|
||||
// tell that we have finished to work on this file
|
||||
$em->beginTransaction();
|
||||
$this->repoWorker->reconnect();
|
||||
$em->getConnection()->beginTransaction();
|
||||
try {
|
||||
$workerRunningJob->setStatus(WorkerRunningJob::FINISHED);
|
||||
$workerRunningJob->setFinished(new \DateTime('now'));
|
||||
@@ -178,7 +180,17 @@ class SubdefCreationWorker implements WorkerInterface
|
||||
$em->flush();
|
||||
$em->commit();
|
||||
} catch (\Exception $e) {
|
||||
$em->rollback();
|
||||
try {
|
||||
$em->getConnection()->beginTransaction();
|
||||
$workerRunningJob->setStatus(WorkerRunningJob::FINISHED);
|
||||
$em->persist($workerRunningJob);
|
||||
$em->flush();
|
||||
$em->commit();
|
||||
} catch (\Exception $e) {
|
||||
$this->messagePublisher->pushLog("rollback on recordID :" . $workerRunningJob->getRecordId());
|
||||
$em->rollback();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -82,6 +82,7 @@ class WriteMetadatasWorker implements WorkerInterface
|
||||
|
||||
// tell that a file is in used to create subdef
|
||||
$em = $this->getEntityManager();
|
||||
$this->repoWorker->reconnect();
|
||||
$em->beginTransaction();
|
||||
|
||||
try {
|
||||
@@ -245,6 +246,7 @@ class WriteMetadatasWorker implements WorkerInterface
|
||||
|
||||
|
||||
// tell that we have finished to work on this file
|
||||
$this->repoWorker->reconnect();
|
||||
$em->beginTransaction();
|
||||
try {
|
||||
$workerRunningJob->setStatus(WorkerRunningJob::FINISHED);
|
||||
|
Reference in New Issue
Block a user