From: Vincent Vanwaelscappel Date: Wed, 27 Dec 2023 11:39:15 +0000 (+0100) Subject: wip #6598 X-Git-Url: http://git.cubedesigners.com/?a=commitdiff_plain;h=6daa3e5d33672e282b3816797b389a2907b99730;p=fluidbook-toolbox.git wip #6598 --- diff --git a/app/Fluidbook/Farm.php b/app/Fluidbook/Farm.php index ee04f0b83..1701767f8 100644 --- a/app/Fluidbook/Farm.php +++ b/app/Fluidbook/Farm.php @@ -15,20 +15,22 @@ use Mockery\Exception; class Farm { protected static $_outPDF = []; - //protected static $_forceServer = false; + protected static $_forceServer = false; - protected static $_forceServer = 'alphaville'; + //protected static $_forceServer = 'alphaville'; + + const LOCAL_SERVER = "dracula"; protected static $_region = Region::EUROPE; protected static $_farmServers = [ ['name' => 'alphaville', 'host' => 'fluidbook-processfarm', 'port' => 9000, 'weight' => 12, 'region' => Region::EUROPE], ['name' => 'brazil', 'host' => 'brazil.cubedesigners.com', 'weight' => 6, 'region' => Region::USA], - ['name' => 'dracula', 'host' => 'dracula.cubedesigners.com', 'weight' => 4, 'region' => Region::EUROPE], + ['name' => 'dracula', 'host' => 'dracula.cubedesigners.com', 'weight' => 1, 'region' => Region::EUROPE], ['name' => 'dobermann', 'host' => 'dobermann.cubedesigners.com', 'weight' => 6, 'region' => Region::EUROPE], ['name' => 'elephantman', 'host' => 'paris.cubedesigners.com', 'weight' => 2, 'region' => Region::EUROPE], ['name' => 'fastandfurious', 'host' => 'fastandfurious.cubedesigners.com', 'weight' => 2, 'region' => Region::EUROPE], - ['name' => 'godzilla', 'host' => 'godzilla.cubedesigners.com', 'weight' => 1, 'region' => Region::EUROPE], + //['name' => 'godzilla', 'host' => 'godzilla.cubedesigners.com', 'weight' => 1, 'region' => Region::EUROPE], ['name' => 'her', 'host' => 'her2.cubedesigners.com', 'weight' => 4, 'region' => Region::EUROPE], ['name' => 'isleofdogs', 'host' => 'paris.cubedesigners.com', 'port' => 9458, 'weight' => 2, 'region' => Region::EUROPE], ['name' => 'jumanji', 'host' => 'paris.cubedesigners.com', 'port' => 9459, 'weight' => 2, 'region' => Region::EUROPE], @@ -71,7 +73,7 @@ class Farm return self::$_farmServers; } - public static function pickOneServer() + public static function pickOneServer($preferLocal) { $hat = []; $pingCache = self::_pingCache(); @@ -87,6 +89,10 @@ class Farm if (self::$_forceServer && $farmServer['name'] === self::$_forceServer) { return $farmServer; } + if ($preferLocal && $farmServer['name'] === self::LOCAL_SERVER) { + $hat = [$k]; + break; + } for ($i = 0; $i < $farmServer['weight']; $i++) { if ($farmServer['region'] === self::getRegion()) { $hat[] = $k; @@ -192,7 +198,7 @@ class Farm { return self::_getFile(['operation' => 'fixpdf', 'pdf' => $pdf, - 'out' => $out], 0,false); + 'out' => $out], 0, false, true); } public static function cutPDF($pdf, $mode, $out) @@ -201,7 +207,7 @@ class Farm 'pdf' => $pdf, 'out' => $out, 'mode' => $mode, - ], 0,false); + ], 0, false, true); } public static function trimPDF($pdf, $out) @@ -209,21 +215,21 @@ class Farm return self::_getFile(['operation' => 'trimpdf', 'pdf' => $pdf, 'out' => $out, - ], 0,false); + ], 0, false, true); } public static function splitPDF($pdf, $out) { return self::_getFile(['operation' => 'splitpdf', 'pdf' => $pdf, - 'out' => $out], 0,false); + 'out' => $out], 0, false, true); } public static function extractLinks($pdf, $out) { return self::_getFile(['operation' => 'extractlinks', 'pdf' => $pdf, - 'out' => $out], 0,false); + 'out' => $out], 0, false, true); } public static function extractTexts($pdf, $out, $mode, $extractionMethod, $ignoreSeparators) @@ -234,7 +240,7 @@ class Farm 'out' => $out, 'mode' => $mode, 'method' => $extractionMethod, - 'ignoreseparators' => $ignoreSeparators], 0,false); + 'ignoreseparators' => $ignoreSeparators], 0, false, true); } public static function extractHighlightsData($pdf, $out, $mode, $ignoreSeparators) @@ -244,16 +250,16 @@ class Farm 'pdf' => $pdf, 'out' => $out, 'mode' => $mode, - 'ignoreseparators' => $ignoreSeparators], 0,false); + 'ignoreseparators' => $ignoreSeparators], 0, false, true); } /** * @throws \Exception */ - protected static function _getFile($params, $attempts = 3, $checkOutput = true) + protected static function _getFile($params, $attempts = 3, $checkOutput = true, $preferLocal = false) { $start = microtime(true); - $farmer = self::pickOneServer(); + $farmer = self::pickOneServer($preferLocal); $params['toolbox'] = '1';