mirror of
https://github.com/alchemy-fr/Phraseanet.git
synced 2025-10-24 10:23:17 +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();
|
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();
|
$repoWorker = $this->getRepoWorker();
|
||||||
$em = $repoWorker->getEntityManager();
|
$em = $repoWorker->getEntityManager();
|
||||||
|
// check connection an re-connect if needed
|
||||||
|
$repoWorker->reconnect();
|
||||||
|
|
||||||
$workerRunningJob = $repoWorker->findOneBy([
|
$workerRunningJob = $repoWorker->findOneBy([
|
||||||
'databoxId' => $event->getRecord()->getDataboxId(),
|
'databoxId' => $event->getRecord()->getDataboxId(),
|
||||||
'recordId' => $event->getRecord()->getRecordId(),
|
'recordId' => $event->getRecord()->getRecordId(),
|
||||||
@@ -108,6 +111,7 @@ class RecordSubscriber implements EventSubscriberInterface
|
|||||||
'workOn' => $event->getSubdefName()
|
'workOn' => $event->getSubdefName()
|
||||||
]);
|
]);
|
||||||
|
|
||||||
|
if ($workerRunningJob) {
|
||||||
$em->beginTransaction();
|
$em->beginTransaction();
|
||||||
try {
|
try {
|
||||||
$em->remove($workerRunningJob);
|
$em->remove($workerRunningJob);
|
||||||
@@ -116,6 +120,7 @@ class RecordSubscriber implements EventSubscriberInterface
|
|||||||
} catch (\Exception $e) {
|
} catch (\Exception $e) {
|
||||||
$em->rollback();
|
$em->rollback();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
$this->messagePublisher->publishMessage(
|
$this->messagePublisher->publishMessage(
|
||||||
$payload,
|
$payload,
|
||||||
@@ -223,6 +228,9 @@ class RecordSubscriber implements EventSubscriberInterface
|
|||||||
|
|
||||||
$repoWorker = $this->getRepoWorker();
|
$repoWorker = $this->getRepoWorker();
|
||||||
$em = $repoWorker->getEntityManager();
|
$em = $repoWorker->getEntityManager();
|
||||||
|
// check connection an re-connect if needed
|
||||||
|
$repoWorker->reconnect();
|
||||||
|
|
||||||
$workerRunningJob = $repoWorker->findOneBy([
|
$workerRunningJob = $repoWorker->findOneBy([
|
||||||
'databoxId' => $event->getRecord()->getDataboxId(),
|
'databoxId' => $event->getRecord()->getDataboxId(),
|
||||||
'recordId' => $event->getRecord()->getRecordId(),
|
'recordId' => $event->getRecord()->getRecordId(),
|
||||||
@@ -230,6 +238,7 @@ class RecordSubscriber implements EventSubscriberInterface
|
|||||||
'workOn' => $event->getSubdefName()
|
'workOn' => $event->getSubdefName()
|
||||||
]);
|
]);
|
||||||
|
|
||||||
|
if ($workerRunningJob) {
|
||||||
$em->beginTransaction();
|
$em->beginTransaction();
|
||||||
try {
|
try {
|
||||||
$em->remove($workerRunningJob);
|
$em->remove($workerRunningJob);
|
||||||
@@ -238,6 +247,7 @@ class RecordSubscriber implements EventSubscriberInterface
|
|||||||
} catch (\Exception $e) {
|
} catch (\Exception $e) {
|
||||||
$em->rollback();
|
$em->rollback();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
$this->messagePublisher->publishMessage(
|
$this->messagePublisher->publishMessage(
|
||||||
$payload,
|
$payload,
|
||||||
|
|||||||
@@ -81,6 +81,7 @@ class SubdefCreationWorker implements WorkerInterface
|
|||||||
|
|
||||||
// tell that a file is in used to create subdef
|
// tell that a file is in used to create subdef
|
||||||
$em = $this->repoWorker->getEntityManager();
|
$em = $this->repoWorker->getEntityManager();
|
||||||
|
$this->repoWorker->reconnect();
|
||||||
$em->beginTransaction();
|
$em->beginTransaction();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
@@ -108,13 +109,13 @@ class SubdefCreationWorker implements WorkerInterface
|
|||||||
try {
|
try {
|
||||||
$this->subdefGenerator->generateSubdefs($record, $wantedSubdef);
|
$this->subdefGenerator->generateSubdefs($record, $wantedSubdef);
|
||||||
} catch (\Exception $e) {
|
} catch (\Exception $e) {
|
||||||
$em->beginTransaction();
|
|
||||||
try {
|
try {
|
||||||
|
$this->repoWorker->reconnect();
|
||||||
|
$em->getConnection()->beginTransaction();
|
||||||
$em->remove($workerRunningJob);
|
$em->remove($workerRunningJob);
|
||||||
$em->flush();
|
$em->flush();
|
||||||
$em->commit();
|
$em->commit();
|
||||||
} catch (\Exception $e) {
|
} catch (\Exception $e) {
|
||||||
$em->rollback();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -170,7 +171,8 @@ class SubdefCreationWorker implements WorkerInterface
|
|||||||
$this->indexer->flushQueue();
|
$this->indexer->flushQueue();
|
||||||
|
|
||||||
// tell that we have finished to work on this file
|
// tell that we have finished to work on this file
|
||||||
$em->beginTransaction();
|
$this->repoWorker->reconnect();
|
||||||
|
$em->getConnection()->beginTransaction();
|
||||||
try {
|
try {
|
||||||
$workerRunningJob->setStatus(WorkerRunningJob::FINISHED);
|
$workerRunningJob->setStatus(WorkerRunningJob::FINISHED);
|
||||||
$workerRunningJob->setFinished(new \DateTime('now'));
|
$workerRunningJob->setFinished(new \DateTime('now'));
|
||||||
@@ -178,8 +180,18 @@ class SubdefCreationWorker implements WorkerInterface
|
|||||||
$em->flush();
|
$em->flush();
|
||||||
$em->commit();
|
$em->commit();
|
||||||
} catch (\Exception $e) {
|
} catch (\Exception $e) {
|
||||||
|
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();
|
$em->rollback();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -82,6 +82,7 @@ class WriteMetadatasWorker implements WorkerInterface
|
|||||||
|
|
||||||
// tell that a file is in used to create subdef
|
// tell that a file is in used to create subdef
|
||||||
$em = $this->getEntityManager();
|
$em = $this->getEntityManager();
|
||||||
|
$this->repoWorker->reconnect();
|
||||||
$em->beginTransaction();
|
$em->beginTransaction();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
@@ -245,6 +246,7 @@ class WriteMetadatasWorker implements WorkerInterface
|
|||||||
|
|
||||||
|
|
||||||
// tell that we have finished to work on this file
|
// tell that we have finished to work on this file
|
||||||
|
$this->repoWorker->reconnect();
|
||||||
$em->beginTransaction();
|
$em->beginTransaction();
|
||||||
try {
|
try {
|
||||||
$workerRunningJob->setStatus(WorkerRunningJob::FINISHED);
|
$workerRunningJob->setStatus(WorkerRunningJob::FINISHED);
|
||||||
|
|||||||
Reference in New Issue
Block a user