Skip to content
Snippets Groups Projects
Commit 896ace12 authored by Patrick Barroca's avatar Patrick Barroca :grin:
Browse files

hotline #43155 : better handling off batch errors in integration phase

parent e2374a3a
Branches
Tags 7.7.28
4 merge requests!2080Sandbox detach zf from storm,!1943Hotline master,!1942Stable,!1938hotline #43155 : better handling off batch errors in integration phase
- ticket #43155 : Intégrations: amélioration de la gestion des erreurs pendant l'éxécution des batchs
\ No newline at end of file
......@@ -22,7 +22,7 @@
class Class_BatchLoader extends Storm_Model_Loader {
public function getKnownTypes() {
return array_merge($this->getRessourcesNumeriqueTypes(),
return array_merge(Class_Batch::getRessourcesNumeriqueTypes(),
[
Class_Batch_Typo3::TYPE => new Class_Batch_Typo3(),
Class_Batch_PanierNotice::TYPE => new Class_Batch_PanierNotice(),
......@@ -54,7 +54,7 @@ class Class_BatchLoader extends Storm_Model_Loader {
public function getKnownType($type) {
return $this->getKnownTypes()[$type];
return Class_Batch::getKnownTypes()[$type];
}
......@@ -147,4 +147,3 @@ class Class_Batch extends Storm_Model_Abstract {
? $closure($batch) : $default;
}
}
?>
......@@ -34,7 +34,7 @@ class Class_Cosmogramme_Integration_PhaseBatchs
protected function _execute() {
if (!$this->_phase->isCron()) {
$this->_log->ecrire('Les batchs ne sont traités qu\'en mode cron.');
$this->_log->ecrire($this->_('Les batchs ne sont traités qu\'en mode cron.'));
return;
}
......@@ -60,13 +60,20 @@ class Class_Cosmogramme_Integration_PhaseBatchs
protected function _runOne($batch) {
$this->_log->ecrire('<span class="vert">' . $batch->getLibelle().':');
$this->_log->addSuccess($batch->getLibelle());
$this->_setData('pointeur_reprise', $batch->getId());
$batch->runWithLogger($this);
$this->_log->ecrire(' OK</span><br/>');
$this->_log
->ecrire(sprintf('<span class="vert">Temps de traitement : %s</span><br/>',
$this->_chrono->endFile()));
try {
$batch->runWithLogger($this);
$this->_log->addSuccess($this->_('OK, temps de traitement : %s',
$this->_chrono->endFile()));
} catch (Exception $e) {
$this->_log->addError($this->_('Erreur lors de l\'execution du batch %s',
$batch->getLibelle()));
$this->_log->addError($e->getMessage());
$this->_log->addError($e->getTraceAsString());
}
$this->_chrono->startOnFile();
}
......
......@@ -136,20 +136,41 @@ class PhaseBatchsCronRunWithLoggerTest extends PhaseBatchsTestCase {
protected function _prepareFixtures() {
$this->fixture('Class_Batch',
['id' => 33,
'type' => 'ThrowingBatch']);
$this->fixture('Class_Batch',
['id' => 34,
'type' => 'TestingTest']);
$this->_batch = new Class_Cosmogramme_Integration_PhaseTestingBatch();
$throwing = $this->mock();
$this
->onLoaderOfModel('Class_Batch')
->whenCalled('getKnownType')->with('TestingTest')->answers($this->_batch);
->whenCalled('getKnownType')
->with('ThrowingBatch')
->answers($throwing
->whenCalled('getLabel')->answers('ThrowingBatch')
->whenCalled('setLogger')->answers($throwing)
->whenCalled('run')->willDo(function() { throw new RuntimeException('Oh!'); }))
->whenCalled('getKnownType')->with('TestingTest')->answers($this->_batch)
;
}
/** @test */
public function shouldDisplayThrowingBatchErrorInBatchLog() {
$this->assertLogContains('Erreur lors de l\'execution du batch ThrowingBatch Oh!');
}
/** @test */
public function shouldDisplayBatchLog() {
public function shouldDisplayTestingTestInBatchLog() {
$this->assertLogContains('Testing test log');
}
}
......
......@@ -36,7 +36,7 @@ abstract class Class_Cosmogramme_Integration_PhaseTestCase extends ModelTestCase
profil_donnees::clearCache();
$append_log = function($content) { $this->_log_content .= $content; };
$append_log = function($content) { $this->_log_content .= ' ' . $content; };
$this->_log = $this->mock()
->whenCalled('addError')->willDo($append_log)
->whenCalled('addSuccess')->willDo($append_log)
......@@ -72,7 +72,8 @@ abstract class Class_Cosmogramme_Integration_PhaseTestCase extends ModelTestCase
return (new $class_name($this->_getPreviousPhase(),
$this->_log,
$this->_chrono))
->setPrinter($this->_printer);
->setPrinter($this->_printer)
->setMemoryCleaner(function() { });
}
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment