Created
June 22, 2014 19:43
-
-
Save brgmn/04ba968f163618048538 to your computer and use it in GitHub Desktop.
Catch database exception (if timed out) and rebuild the connection in long running TYPO3 Flow commands
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
//... | |
class JobsCommandController extends CommandController { | |
public function workCommand($queue, $verbose = FALSE) { | |
do { | |
try { | |
$job = $this->jobManager->waitAndExecute($queueName); | |
if ($job !== NULL) { | |
$this->printLineIf('Processed job "%s"', $verbose, array($job->getLabel())); | |
$this->persistenceManager->clearState(); | |
} | |
} catch (Exception $exception) { | |
$this->printLineIf($exception->getMessage(), $verbose); | |
} catch (\TYPO3\Flow\Persistence\Doctrine\Exception\DatabaseException $exception) { | |
/** | |
* CATCH DATABSE EXCEPTION AND RECONNECT! (PDO does not support this by default) | |
* Reinitialize database connection if connection timed out. | |
* You shoult also have a look at the mysql-servers wait_timeout option (should not be to low) | |
*/ | |
$this->doctrineEntityManager->getConnection()->close(); | |
$this->doctrineEntityManager->getConnection()->connect(); | |
} catch (\Exception $exception) { | |
$this->printLineIf('EXCEPTION: "%s"', $verbose, array($exception->getMessage())); | |
$this->systemLogger->logException($exception); | |
} | |
} while (TRUE); | |
} | |
} | |
//.... | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment