]> _ Git - cubeextranet.git/commitdiff
wip #5220 @0.5
authorvincent@cubedesigners.com <vincent@cubedesigners.com@f5622870-0f3c-0410-866d-9cb505b7a8ef>
Tue, 12 Apr 2022 08:41:07 +0000 (08:41 +0000)
committervincent@cubedesigners.com <vincent@cubedesigners.com@f5622870-0f3c-0410-866d-9cb505b7a8ef>
Tue, 12 Apr 2022 08:41:07 +0000 (08:41 +0000)
inc/ws/Controlleur/class.ws.maintenance.php
inc/ws/Metier/class.ws.document.php

index d413a4f85c4aafddec1330dfea1cb38211238917..a6b9c95460a0f04513d02e6dded0d4bf96ef2f93 100644 (file)
@@ -1836,8 +1836,9 @@ class wsMaintenance
 
     public static function updateFarm()
     {
-        foreach (wsDocument::getFarmServers() as $farmer) {
-            echo '<h2>' . $farmer['host'] . '</h2><pre>';
+
+        foreach (wsDocument::getFarmServers() as $id => $farmer) {
+            echo '<h2>' . $farmer['host'] . ' (' . $id . ')</h2><pre>';
             $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 '<h2>' . $farmer['host'] . ' (' . $id . ')</h2>';
+            $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 '<p>' . ($ok ? 'OK' : 'KO') . ' : ' . $cl->output . '</p>';
+
+            $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;
index 7d14588b9cc22a327d74c9e8f02bfe056a768f0f..de822dbf39c32bbdae99cfbfc7be1b423a151c3e 100644 (file)
@@ -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);
         }