From 5269c0352cde90fac55d83c9ad2ae738809810e4 Mon Sep 17 00:00:00 2001 From: Laurent Laffont <llaffont@afi-sa.fr> Date: Tue, 7 Dec 2021 15:53:49 +0100 Subject: [PATCH] hotline #138070 delay autocompletion batchs run Ensure they are run after pseudo records indexation (and a few other phases) so all records can be indexed for autocompletion files generation --- VERSIONS_HOTLINE/138070 | 1 + cosmogramme/php/integre_traite_main.php | 19 ++-- .../Class/Batch/AutocompleteRecordAuthor.php | 4 +- .../Class/Batch/AutocompleteRecordTitle.php | 4 +- .../Integration/PhaseAutocompleteBatchs.php | 41 +++++++++ .../Cosmogramme/Integration/PhaseBatchs.php | 24 +++-- .../PhaseAutocompleteBatchsTest.php | 89 +++++++++++++++++++ .../Integration/PhaseBatchsTest.php | 36 ++++++-- 8 files changed, 190 insertions(+), 28 deletions(-) create mode 100644 VERSIONS_HOTLINE/138070 create mode 100644 library/Class/Cosmogramme/Integration/PhaseAutocompleteBatchs.php create mode 100644 tests/library/Class/Cosmogramme/Integration/PhaseAutocompleteBatchsTest.php diff --git a/VERSIONS_HOTLINE/138070 b/VERSIONS_HOTLINE/138070 new file mode 100644 index 00000000000..30a8a2e19de --- /dev/null +++ b/VERSIONS_HOTLINE/138070 @@ -0,0 +1 @@ + - ticket #138070 : Cosmogramme : les batchs de génération des fichiers d'autocomplétion sont executés après l'indexation des pseudo-notices pour que celles-ci soient prises en compte \ No newline at end of file diff --git a/cosmogramme/php/integre_traite_main.php b/cosmogramme/php/integre_traite_main.php index b17f30cd2f4..541683d6559 100644 --- a/cosmogramme/php/integre_traite_main.php +++ b/cosmogramme/php/integre_traite_main.php @@ -187,17 +187,14 @@ if (!$should_skip_records) { // ---------------------------------------------------------------- // Batch // ---------------------------------------------------------------- -if ($phase >= 0 and $phase < 0.2) { - startIntegrationPhase('Batchs'); - $phase = 0.2; -} +startIntegrationPhase('Batchs'); if (!$should_skip_records) { // ---------------------------------------------------------------- // PSEUDO-NOTICES - cms rss sitotheque et albums (phase 0.1 a 0.6) // ---------------------------------------------------------------- - if ($phase > 0.1 and $phase < 1) { + if ($phase < 1) { $log->log('<h4>Pseudo-notices : CMS</h4>'); startIntegrationPhase('PseudoRecordCms'); startIntegrationPhase('PseudoRecordRss'); @@ -218,6 +215,7 @@ if (!$should_skip_records) { $log->log('<h4>Suppression des notices sans exemplaire</h4>'); startIntegrationPhase('DeleteRecordWithoutItem'); + // ---------------------------------------------------------------- // INDEXATION DES ARTICLES DE PERIODIQUES // ---------------------------------------------------------------- @@ -243,9 +241,16 @@ if (!$should_skip_records) { } // ---------------------------------------------------------------- - // Recalcul des facettes bibliothèque (phases 7 et 7.1) + // Recalcul des facettes bibliothèque (phase 7) // ---------------------------------------------------------------- startIntegrationPhase('ItemFacets'); + + + // ---------------------------------------------------------------- + // Build autocompletion files (phase 7.1) + // ---------------------------------------------------------------- + startIntegrationPhase('AutocompleteBatchs'); + } $phase = 7.5; @@ -489,4 +494,4 @@ function restaureContext() $chrono_fichier->timeStart = $timeStart_fichier; $chrono100notices->timeStart = $timeStart_100notices; unset($_SESSION["reprise"]); -} \ No newline at end of file +} diff --git a/library/Class/Batch/AutocompleteRecordAuthor.php b/library/Class/Batch/AutocompleteRecordAuthor.php index 1e5ec064762..266d023f24a 100644 --- a/library/Class/Batch/AutocompleteRecordAuthor.php +++ b/library/Class/Batch/AutocompleteRecordAuthor.php @@ -24,7 +24,7 @@ class Class_Batch_AutocompleteRecordAuthor extends Class_Batch_Abstract { const TYPE = 'AUTOCOMPLETE_RECORD_AUTHOR'; public function getLabel() { - return $this->_("Indexer les auteurs de notice pour l'autocompletion"); + return $this->_("Indexer les auteurs de notice pour l'autocomplétion"); } public function run() { @@ -35,4 +35,4 @@ class Class_Batch_AutocompleteRecordAuthor extends Class_Batch_Abstract { return Class_Autocomplete_Index::indexRecordsAuthor($params); } } -?> \ No newline at end of file +?> diff --git a/library/Class/Batch/AutocompleteRecordTitle.php b/library/Class/Batch/AutocompleteRecordTitle.php index d98906d5ec8..f7fc8f0a162 100644 --- a/library/Class/Batch/AutocompleteRecordTitle.php +++ b/library/Class/Batch/AutocompleteRecordTitle.php @@ -24,7 +24,7 @@ class Class_Batch_AutocompleteRecordTitle extends Class_Batch_Abstract { const TYPE = 'AUTOCOMPLETE_RECORD_TITLE'; public function getLabel() { - return $this->_("Indexer les titres de notice pour l'autocompletion"); + return $this->_('Indexer les titres de notice pour l\'autocomplétion'); } public function run() { @@ -35,4 +35,4 @@ class Class_Batch_AutocompleteRecordTitle extends Class_Batch_Abstract { return Class_Autocomplete_Index::indexRecordsTitle($params); } } -?> \ No newline at end of file +?> diff --git a/library/Class/Cosmogramme/Integration/PhaseAutocompleteBatchs.php b/library/Class/Cosmogramme/Integration/PhaseAutocompleteBatchs.php new file mode 100644 index 00000000000..cf21b758e6a --- /dev/null +++ b/library/Class/Cosmogramme/Integration/PhaseAutocompleteBatchs.php @@ -0,0 +1,41 @@ +<?php +/** + * Copyright (c) 2012-2021, Agence Française Informatique (AFI). All rights reserved. + * + * BOKEH is free software; you can redistribute it and/or modify + * it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE as published by + * the Free Software Foundation. + * + * There are special exceptions to the terms and conditions of the AGPL as it + * is applied to this software (see README file). + * + * BOKEH is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU AFFERO GENERAL PUBLIC LICENSE for more details. + * + * You should have received a copy of the GNU AFFERO GENERAL PUBLIC LICENSE + * along with BOKEH; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + */ + + +class Class_Cosmogramme_Integration_PhaseAutocompleteBatchs + extends Class_Cosmogramme_Integration_PhaseBatchs { + + const MY_ID = 7.1; + + protected $_label = 'Execution des batchs pour l\'autocomplétion'; + + protected function _previousPhaseIds() { + return [7]; + } + + + protected function _batchsToRunDo(callable $callable) { + array_map($callable, + Class_Batch::findAllWithDefaults(['order' => 'id', + 'type' => [Class_Batch_AutocompleteRecordTitle::TYPE, + Class_Batch_AutocompleteRecordAuthor::TYPE]])); + } +} diff --git a/library/Class/Cosmogramme/Integration/PhaseBatchs.php b/library/Class/Cosmogramme/Integration/PhaseBatchs.php index 43e258cb910..f3f93859a14 100644 --- a/library/Class/Cosmogramme/Integration/PhaseBatchs.php +++ b/library/Class/Cosmogramme/Integration/PhaseBatchs.php @@ -22,6 +22,7 @@ class Class_Cosmogramme_Integration_PhaseBatchs extends Class_Cosmogramme_Integration_PhaseAbstract { + const MY_ID=0.1; protected $_label = 'Execution des batchs programmés'; @@ -38,17 +39,24 @@ class Class_Cosmogramme_Integration_PhaseBatchs return; } - foreach(Class_Batch::findAllWithDefaults(['order' => 'id']) as $batch) { - if ($this->_getData('pointeur_reprise') > $batch->getId()) - continue; - - $this->_runOne($batch); - $this->_cleanMemory(); - } + $this->_batchsToRunDo( + function($batch) { + if ($this->_getData('pointeur_reprise') > $batch->getId()) + return; + $this->_runOne($batch); + $this->_cleanMemory(); + }); } + protected function _batchsToRunDo(callable $callable) { + array_map($callable, + Class_Batch::findAllWithDefaults(['order' => 'id', + 'type not' => [Class_Batch_AutocompleteRecordTitle::TYPE, + Class_Batch_AutocompleteRecordAuthor::TYPE]])); + } + protected function _runOne($batch) { if (!$batch->shouldRun()) { @@ -87,4 +95,4 @@ class Class_Cosmogramme_Integration_PhaseBatchs ->startOnFile() ->startOnRecords(); } -} \ No newline at end of file +} diff --git a/tests/library/Class/Cosmogramme/Integration/PhaseAutocompleteBatchsTest.php b/tests/library/Class/Cosmogramme/Integration/PhaseAutocompleteBatchsTest.php new file mode 100644 index 00000000000..5993e78aa8e --- /dev/null +++ b/tests/library/Class/Cosmogramme/Integration/PhaseAutocompleteBatchsTest.php @@ -0,0 +1,89 @@ +<?php +/** + * Copyright (c) 2012-2021, Agence Française Informatique (AFI). All rights reserved. + * + * BOKEH is free software; you can redistribute it and/or modify + * it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE as published by + * the Free Software Foundation. + * + * There are special exceptions to the terms and conditions of the AGPL as it + * is applied to this software (see README file). + * + * BOKEH is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU AFFERO GENERAL PUBLIC LICENSE for more details. + * + * You should have received a copy of the GNU AFFERO GENERAL PUBLIC LICENSE + * along with BOKEH; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + */ + + +class PhaseAutocompleteBatchsTest extends Class_Cosmogramme_Integration_PhaseTestCase { + protected function _getPreviousPhase() { + return (new Class_Cosmogramme_Integration_Phase(7))->beCron(); + } + + + protected function _buildPhase($name) { + $phase = parent::_buildPhase($name); + $phase->setMemoryCleaner(function() {}); + return $phase; + } + + + protected function _prepareFixtures() { + $this->fixture(Class_Batch::class, + ['id' => 1, + 'pick_day' => '1;2;3;4;5;6;0', + 'type' => Class_Batch_AutocompleteRecordTitle::TYPE]); + + $this->fixture(Class_Batch::class, + ['id' => 2, + 'pick_day' => '1;2;3;4;5;6;0', + 'type' => Class_Batch_AutocompleteRecordAuthor::TYPE]); + + + $this->fixture(Class_Batch::class, + ['id' => 3, + 'pick_day' => '1;2;3;4;5;6;0', + 'type' => 'AnotherBatch']); + + $another_batch = $this->mock(); + $another_batch + ->whenCalled('getLabel')->answers('AnotherBatch') + ->whenCalled('run')->answers(true) + ->whenCalled('setLogger')->answers($another_batch); + + $this + ->onLoaderOfModel(Class_Batch::class) + ->whenCalled('getKnownType') + ->with('AnotherBatch') + ->answers($another_batch); + } + + + public function setUp() { + parent::setUp(); + $this->_buildPhase('AutocompleteBatchs')->run(); + } + + + /** @test */ + public function anotherBatchShouldNotRun() { + $this->assertNotLogContains('AnotherBatch'); + } + + + /** @test */ + public function autocompleteRecordTitleBatchShouldRun() { + $this->assertLogContains('Indexer les titres de notice pour l\'autocomplétion'); + } + + + /** @test */ + public function autocompleteRecordAuthorBatchShouldRun() { + $this->assertLogContains('Indexer les auteurs de notice pour l\'autocomplétion'); + } +} diff --git a/tests/library/Class/Cosmogramme/Integration/PhaseBatchsTest.php b/tests/library/Class/Cosmogramme/Integration/PhaseBatchsTest.php index b9e4431b984..88e9d072776 100644 --- a/tests/library/Class/Cosmogramme/Integration/PhaseBatchsTest.php +++ b/tests/library/Class/Cosmogramme/Integration/PhaseBatchsTest.php @@ -35,7 +35,7 @@ abstract class PhaseBatchsTestCase extends Class_Cosmogramme_Integration_PhaseTe $time = new TimeSourceForTest('2017-08-29'); Class_Batch::setTimeSource($time); // tuesday for pick_day - $this->fixture('Class_Batch', + $this->fixture(Class_Batch::class, ['id' => 34, 'pick_day' => '2', 'type' => 'TestingTest']); @@ -46,7 +46,7 @@ abstract class PhaseBatchsTestCase extends Class_Cosmogramme_Integration_PhaseTe ->whenCalled('run')->answers(true) ->whenCalled('setLogger')->answers($this->_batch); - $this->_not_runnable = $this->fixture('Class_Batch', + $this->_not_runnable = $this->fixture(Class_Batch::class, ['id' => 99, 'pick_day' => '3', 'type' => 'TestingNotRunnableTest']); @@ -57,7 +57,7 @@ abstract class PhaseBatchsTestCase extends Class_Cosmogramme_Integration_PhaseTe $this - ->onLoaderOfModel('Class_Batch') + ->onLoaderOfModel(Class_Batch::class) ->whenCalled('getKnownType')->with('TestingTest')->answers($this->_batch) ->whenCalled('getKnownType')->with('TestingNotRunnableTest')->answers($this->_not_runnable_batch); } @@ -82,6 +82,7 @@ abstract class PhaseBatchsTestCase extends Class_Cosmogramme_Integration_PhaseTe + class PhaseBatchsManualRunTest extends PhaseBatchsTestCase { protected function _getPreviousPhase() { return new Class_Cosmogramme_Integration_Phase(0); @@ -108,6 +109,7 @@ class PhaseBatchsManualRunTest extends PhaseBatchsTestCase { + class PhaseBatchsCronRunTest extends PhaseBatchsTestCase { protected function _getPreviousPhase() { return (new Class_Cosmogramme_Integration_Phase(0)) @@ -148,12 +150,11 @@ EOT; public function shouldDisplayNotRunnableBatchisNotPlanned() { $this->assertLogContains('La tâche Testing Not Runnable Batch n\'est pas plannifiée aujourd\'hui'); } - - } + class PhaseBatchsCronRunWithLoggerTest extends PhaseBatchsTestCase { protected function _getPreviousPhase() { return (new Class_Cosmogramme_Integration_Phase(0)) @@ -162,21 +163,31 @@ class PhaseBatchsCronRunWithLoggerTest extends PhaseBatchsTestCase { protected function _prepareFixtures() { - $this->fixture('Class_Batch', + $this->fixture(Class_Batch::class, ['id' => 33, 'type' => 'ThrowingBatch', 'pick_day' => '1;2;3;4;5;6;0']); - $this->fixture('Class_Batch', + $this->fixture(Class_Batch::class, ['id' => 34, 'type' => 'TestingTest', 'pick_day' => '1;2;3;4;5;6;0']); + $this->fixture(Class_Batch::class, + ['id' => 35, + 'pick_day' => '1;2;3;4;5;6;0', + 'type' => Class_Batch_AutocompleteRecordTitle::TYPE]); + + $this->fixture(Class_Batch::class, + ['id' => 36, + 'pick_day' => '1;2;3;4;5;6;0', + 'type' => Class_Batch_AutocompleteRecordAuthor::TYPE]); + $this->_batch = new Class_Cosmogramme_Integration_PhaseTestingBatch(); $throwing = $this->mock(); $this - ->onLoaderOfModel('Class_Batch') + ->onLoaderOfModel(Class_Batch::class) ->whenCalled('getKnownType') ->with('ThrowingBatch') @@ -206,10 +217,17 @@ EOT; public function shouldDisplayTestingTestInBatchLog() { $this->assertLogContains('Testing test log'); } + + + /** @test */ + public function autocompleteBatchsShouldNotBeExecutedAsTheyHaveASeparateRun() { + $this->assertNotLogContains('autocomplétion'); + } } + class Class_Cosmogramme_Integration_PhaseTestingBatch extends Class_Batch_Abstract { public function getLabel() { return 'TestingTest batch'; @@ -223,8 +241,8 @@ class Class_Cosmogramme_Integration_PhaseTestingBatch extends Class_Batch_Abstra -class PhaseBatchsCronRunWithDefaultsTest extends PhaseBatchsTestCase { +class PhaseBatchsCronRunWithDefaultsTest extends PhaseBatchsTestCase { protected function _getPreviousPhase() { return (new Class_Cosmogramme_Integration_Phase(0)) ->beCron(); -- GitLab