diff --git a/VERSIONS_HOTLINE/43155 b/VERSIONS_HOTLINE/43155 new file mode 100644 index 0000000000000000000000000000000000000000..d5150ddfa30cffa22f83936065c840bfea3b3fef --- /dev/null +++ b/VERSIONS_HOTLINE/43155 @@ -0,0 +1 @@ + - ticket #43155 : Intégrations: amélioration de la gestion des erreurs pendant l'éxécution des batchs \ No newline at end of file diff --git a/library/Class/Batch.php b/library/Class/Batch.php index 8cb6f3098cd7a6485d691038f70443f47c4ef494..db5f1bc452a5f8f6b5f111511f8c53ae42f12dcb 100644 --- a/library/Class/Batch.php +++ b/library/Class/Batch.php @@ -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; } } -?> diff --git a/library/Class/Cosmogramme/Integration/PhaseBatchs.php b/library/Class/Cosmogramme/Integration/PhaseBatchs.php index 56106347c28881d061e6e749f352ff6479761d9d..c23abfc73144dcc40d6c2c085806f246a17da174 100644 --- a/library/Class/Cosmogramme/Integration/PhaseBatchs.php +++ b/library/Class/Cosmogramme/Integration/PhaseBatchs.php @@ -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(); } diff --git a/tests/library/Class/Cosmogramme/Integration/PhaseBatchsTest.php b/tests/library/Class/Cosmogramme/Integration/PhaseBatchsTest.php index 5814fa6d1156f02f1424f07a956701aa77417724..d41127aedccb2a8fd32601ba429d9783ace0cbcc 100644 --- a/tests/library/Class/Cosmogramme/Integration/PhaseBatchsTest.php +++ b/tests/library/Class/Cosmogramme/Integration/PhaseBatchsTest.php @@ -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'); } } diff --git a/tests/library/Class/Cosmogramme/Integration/PhaseTestCase.php b/tests/library/Class/Cosmogramme/Integration/PhaseTestCase.php index d84dcdb0b728fd00957db58aa3870c4d09b26dd1..b07747c62fb59151915c50cd7ff4bc2b5777f56e 100644 --- a/tests/library/Class/Cosmogramme/Integration/PhaseTestCase.php +++ b/tests/library/Class/Cosmogramme/Integration/PhaseTestCase.php @@ -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() { }); }