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

hotline #64396 : add timeout on thumbnail download

parent 4fa5334a
Branches
Tags
3 merge requests!2723Master,!2721Hotline,!2716hotline #64396 : add timeout on thumbnail download
Pipeline #4491 failed with stage
in 49 minutes and 8 seconds
- ticket #64396 : Connecteur Lekiosk : Amélioration du tableau de bord
\ No newline at end of file
- ticket #64396 : Ressources numériques : Amélioration de la récupération des vignettes
\ No newline at end of file
......@@ -21,11 +21,33 @@
class Class_Testing_Command extends Class_Testing_Abstract {
protected $_output,
$_return_var;
protected
$_output,
$_return_var,
$_callable;
public function exec($command) {
$callable = $this->_getCallable();
return $callable($command);
}
/** @category testing */
public function setCallable($callable) {
$this->_callable = $callable;
return $this;
}
protected function _getCallable() {
return $this->_callable
? $this->_callable
: [$this, '_realExec'];
}
protected function _realExec($command) {
$output = [];
$return_var = '';
$result = exec($command, $output, $return_var);
......@@ -35,6 +57,16 @@ class Class_Testing_Command extends Class_Testing_Abstract {
}
public function execTimedScript($timeout, $script_n_args) {
$command = sprintf('timeout %s php %s/../../../scripts/%s',
$timeout,
__DIR__,
$script_n_args);
return $this->exec($command);
}
public function getOutput() {
return $this->_output;
}
......@@ -44,4 +76,3 @@ class Class_Testing_Command extends Class_Testing_Abstract {
return $this->_return_var;
}
}
?>
\ No newline at end of file
......@@ -21,6 +21,8 @@
class Class_WebService_BibNumerique_RessourceNumerique {
use Trait_StaticCommand;
protected static $_logger;
protected
......@@ -336,7 +338,7 @@ class Class_WebService_BibNumerique_RessourceNumerique {
if ($album->save()) {
$this->_debug('new album id: ' . $album->getId());
Class_WebService_BibNumerique_Vignette::getInstance()->updateAlbum($album);
$this->_thumbnailAlbum($album);
}
if ($album->hasErrors())
......@@ -348,6 +350,12 @@ class Class_WebService_BibNumerique_RessourceNumerique {
}
protected function _thumbnailAlbum($album) {
$this->getCommand()
->execTimedScript('10s', 'thumbnail_album.php ' . escapeshellarg($album->getId()));
}
protected function getOrCreateRessourceCategorie() {
$libelle = $this->getRessourceCategorieLibelle();
......
......@@ -24,14 +24,13 @@ trait Trait_StaticCommand {
protected static $_command;
public static function setCommand($command) {
self::$_command = $command;
static::$_command = $command;
}
public static function getCommand() {
if (null !== self::$_command)
return self::$_command;
if (null !== static::$_command)
return static::$_command;
return new Class_Testing_Command();
}
}
?>
\ No newline at end of file
<?php
/**
* Copyright (c) 2012-2017, 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
*/
$album_id = $argv[1];
require_once 'console.php';
if (!$album = Class_Album::find($album_id)) {
printf("Unkown album %s\n", $album_id);
exit(1);
}
Class_WebService_BibNumerique_Vignette::getInstance()->updateAlbum($album);
\ No newline at end of file
<?php
/**
* Copyright (c) 2012-2017, 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_Testing_CommandTest extends ModelTestCase {
protected
$_storm_default_to_volatile = true,
$_last_command;
/** @test */
public function execTimedScriptShouldContainsTimeout() {
(new Class_Testing_Command())
->setCallable(function($command) { $this->_last_command = $command; })
->execTimedScript('10s', 'thumbnail_album.php 44');
$this->assertContains('timeout 10s php ', $this->_last_command);
$this->assertContains('scripts/thumbnail_album.php 44', $this->_last_command);
}
}
......@@ -264,6 +264,11 @@ class CiteDeLaMusiqueParserTest extends ModelTestCase {
$this->_service = new Class_WebService_BibNumerique_CiteDeLaMusique();
Class_WebService_BibNumerique_CiteDeLaMusique::setDefaultHttpClient($this->_http_client);
Class_WebService_BibNumerique_RessourceNumerique::setCommand($this->mock()
->whenCalled('execTimedScript')
->answers('')
);
$this->_service->harvest();
$this->_hommage = Class_Album::find(1);
......@@ -273,6 +278,7 @@ class CiteDeLaMusiqueParserTest extends ModelTestCase {
public function tearDown() {
CiteDeLaMusiqueFixtures::deactivate();
Class_WebService_BibNumerique_RessourceNumerique::setCommand(null);
parent::tearDown();
}
......@@ -347,6 +353,16 @@ class CiteDeLaMusiqueParserTest extends ModelTestCase {
}
/** @test */
public function thumbnailCommandShouldBeCalledWithTimeout() {
$command = Class_WebService_BibNumerique_RessourceNumerique::getCommand();
$this->assertTrue($command->methodHasBeenCalled('execTimedScript'));
$params = $command->getAttributesForLastCallOn('execTimedScript');
$this->assertEquals('10s', $params[0]);
}
/** @test */
public function hommageUrlOrigineShouldBeMediaDotCiteDeLaMusique() {
$this->assertEquals('http://pad.philharmoniedeparis.fr/EXPLOITATION/oaiserver.ashx',
......
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