From: vincent@cubedesigners.com Date: Tue, 12 Apr 2022 08:41:07 +0000 (+0000) Subject: wip #5220 @0.5 X-Git-Url: http://git.cubedesigners.com/?a=commitdiff_plain;h=c7b663445993c16a47005a6ab68daf84559cbb6c;p=cubeextranet.git wip #5220 @0.5 --- diff --git a/inc/ws/Controlleur/class.ws.maintenance.php b/inc/ws/Controlleur/class.ws.maintenance.php index d413a4f85..a6b9c9546 100644 --- a/inc/ws/Controlleur/class.ws.maintenance.php +++ b/inc/ws/Controlleur/class.ws.maintenance.php @@ -1836,8 +1836,9 @@ class wsMaintenance public static function updateFarm() { - foreach (wsDocument::getFarmServers() as $farmer) { - echo '

' . $farmer['host'] . '

';
+
+        foreach (wsDocument::getFarmServers() as $id => $farmer) {
+            echo '

' . $farmer['host'] . ' (' . $id . ')

';
             $cl = new CubeIT_CommandLine('sudo /usr/local/fluidbook_processfarm/bin/update');
             $cl->setSSH($farmer['host'], 'fluidbookfarmer', '', $farmer['port'] ?? 22, '/home/extranet/.ssh/id_rsa');
             $cl->execute();
@@ -1845,6 +1846,25 @@ class wsMaintenance
         }
     }
 
+    public static function pingFarm()
+    {
+        $originalConnectionTimeout = ini_get('default_socket_timeout');
+        ini_set('default_socket_timeout', 5);
+        $pings = [];
+        foreach (wsDocument::getFarmServers() as $id => $farmer) {
+            echo '

' . $farmer['host'] . ' (' . $id . ')

'; + $cl = new CubeIT_CommandLine('/usr/local/fluidbook_processfarm/bin/ping'); + $cl->setSSH($farmer['host'], 'fluidbookfarmer', '', $farmer['port'] ?? 22, '/home/extranet/.ssh/id_rsa'); + $cl->execute(); + $ok = trim($cl->output) == '1'; + echo '

' . ($ok ? 'OK' : 'KO') . ' : ' . $cl->output . '

'; + + $pings[$id] = $ok; + } + file_put_contents(WS_CACHE . '/farmpings', json_encode($pings)); + ini_set('default_socket_timeout', $originalConnectionTimeout); + } + public static function fluidbookFarm($args) { global $core; diff --git a/inc/ws/Metier/class.ws.document.php b/inc/ws/Metier/class.ws.document.php index 7d14588b9..de822dbf3 100644 --- a/inc/ws/Metier/class.ws.document.php +++ b/inc/ws/Metier/class.ws.document.php @@ -58,10 +58,11 @@ class wsDocument extends cubeMetier protected static $_farmServers = [ ['host' => 'elephantman.cubedesigners.com', 'port' => 22822, 'weight' => 1], ['host' => 'fastandfurious.cubedesigners.com', 'port' => 22822, 'weight' => 1], - ['host' => 'paris.cubedesigners.com', 'port' => 22922, 'weight' => 1], - ['host' => 'godzilla.cubedesigners.com', 'weight' => 2], - ['host' => 'dracula.cubedesigners.com', 'weight' => 2], - ['host' => 'her.cubedesigners.com', 'weight' => 3], + ['host' => 'paris.cubedesigners.com', 'port' => 22922, 'weight' => 2], + ['host' => 'paris.cubedesigners.com', 'port' => 22923, 'weight' => 1], + ['host' => 'godzilla.cubedesigners.com', 'weight' => 3], + ['host' => 'dracula.cubedesigners.com', 'weight' => 3], + ['host' => 'her.cubedesigners.com', 'weight' => 4], ]; protected static $resolution2multiply = array(72 => 2, 100 => 2, 150 => 3, 200 => 3, 300 => 3, 450 => 4, 600 => 5); @@ -458,7 +459,12 @@ class wsDocument extends cubeMetier public static function pickOneFarmServer() { $hat = []; + $pings = json_decode(file_get_contents(WS_CACHE . '/farmpings')); + foreach (self::$_farmServers as $k => $farmServer) { + if (!isset($pings[$k]) || !$pings[$k]) { + continue; + } for ($i = 0; $i < $farmServer['weight']; $i++) { $hat[] = $k; } @@ -492,7 +498,9 @@ class wsDocument extends cubeMetier public function _getFile($page, $format = 'jpg', $resolution = 150, $withText = true, $withGraphics = true, $version = 'html', $force = false) { global $core; - if ($core->user->utilisateur_id == 5) { + + $farmTesters = [3, 5]; + if (in_array($core->user->utilisateur_id, $farmTesters)) { return $this->_getFileFarm($page, $format, $resolution, $withText, $withGraphics, $version, $force); }