]> _ Git - cubeextranet.git/commitdiff
wip #5220 @1
authorvincent@cubedesigners.com <vincent@cubedesigners.com@f5622870-0f3c-0410-866d-9cb505b7a8ef>
Fri, 8 Apr 2022 11:51:42 +0000 (11:51 +0000)
committervincent@cubedesigners.com <vincent@cubedesigners.com@f5622870-0f3c-0410-866d-9cb505b7a8ef>
Fri, 8 Apr 2022 11:51:42 +0000 (11:51 +0000)
inc/ws/Controlleur/class.ws.maintenance.php
inc/ws/Metier/class.ws.document.php

index 29796cde4aef77a79c43d2f1bd9a04eded334188..8ce1594efb0b215ec470ddb442fde98e53ddfa02 100644 (file)
@@ -1816,6 +1816,17 @@ class wsMaintenance
 
     }
 
+    public static function updateFarm()
+    {
+        foreach (wsDocument::getFarmServers() as $farmer) {
+            echo '<h2>' . $farmer['host'] . '</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();
+            echo $cl->commande . "\n\n--\n\n" . $cl->output . '</pre>';
+        }
+    }
+
     public static function fluidbookFarm($args)
     {
         global $core;
@@ -1825,7 +1836,27 @@ class wsMaintenance
 
         $dao = new wsDAODocument($core->con);
         $doc = $dao->selectById($doc_id);
-        $doc->_getFileFarm($page, 'jpg', 150, true, true, 'html', true);
+
+        $files = [
+//            ['jpg', 'thumb', true, true, ''],
+//            ['jpg', '300', true, true, 'html'],
+//            ['jpg', '150', true, true, 'html'],
+//            ['jpg', '150', false, true, 'html'],
+//            ['jpg', '150', false, true, 'html'],
+//            ['svg', '150', true, false, 'html'],
+            ['svg', '300', true, false, 'html'],
+//            ['svg', '150', true, true, 'html'],
+//            ['svg', '200', true, true, 'html'],
+        ];
+
+        foreach ($files as $file) {
+            echo '<h2>' . json_encode($file) . '</h2>';
+            $path = $doc->getFile($page, $file[0], $file[1], $file[2], $file[3], $file[4], true);
+            echo '<p>' . $path . '</p>';
+            $path = str_replace('/data1/extranet/www/', 'https://workshop.fluidbook.com/', $path);
+            echo '<img height="200" src="' . $path . '">';
+        }
+
 
     }
 
index 77ccfc5a3f8aad069d0723f35dcef26d7c9e67fd..7946eeb762fe349e8dd2e16ad5d486cbbff9ddc6 100644 (file)
@@ -55,6 +55,15 @@ class wsDocument extends cubeMetier
     const MAX = 5;
     const PNM_FILL = 2;
 
+    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],
+    ];
+
     protected static $resolution2multiply = array(72 => 2, 100 => 2, 150 => 3, 200 => 3, 300 => 3, 450 => 4, 600 => 5);
     // Number section styles
     protected static
@@ -441,27 +450,47 @@ class wsDocument extends cubeMetier
     }
 
 
+    public static function getFarmServers()
+    {
+        return self::$_farmServers;
+    }
+
+    public static function pickOneFarmServer()
+    {
+        $hat = [];
+        foreach (self::$_farmServers as $k => $farmServer) {
+            for ($i = 0; $i < $farmServer['weight']; $i++) {
+                $hat[] = $k;
+            }
+        }
+        shuffle($hat);
+        $i = array_pop($hat);
+        return self::$_farmServers[$i];
+    }
+
     public function _getFileFarm($page, $format = 'jpg', $resolution = 150, $withText = true, $withGraphics = true, $version = 'html', $force = false)
     {
-        $farm = [['host' => 'elephantman.cubedesigners.com', 'port' => 22822]];
-        shuffle($farm);
-        $farmer = array_pop($farm);
+        $farmer = self::pickOneFarmServer();
 
-        $params = ['page' => $page, 'format' => $format, 'resolution' => $resolution, 'withText' => $withText, 'withGraphics' => $withGraphics, 'version' => $version, 'force' => $force, 'out' => $this->out,'resolutionRatio'=>$this->getResolutionRatio(),'mobileRatio'=>$this->getMobileFirstRatio()];
-        $cl = new CubeIT_CommandLine('/usr/local/fluidbook_processfarm/bin/process');
-        $cl->setSSH($farmer['host'], 'fluidbookfarmer', '', $farmer['port'], '/home/extranet/.ssh/id_rsa');
+        $params = ['page' => $page, 'format' => $format, 'resolution' => $resolution, 'withText' => $withText, 'withGraphics' => $withGraphics, 'version' => $version, 'force' => $force, 'out' => $this->out, 'resolutionRatio' => $this->getResolutionRatio(), 'mobileRatio' => $this->getMobileFirstRatio()];
+        $cl = new CubeIT_CommandLine('/usr/local/fluidbook_processfarm/bin/process', null, false);
+        $cl->setSSH($farmer['host'], 'fluidbookfarmer', '', $farmer['port'] ?? 22, '/home/extranet/.ssh/id_rsa');
         $cl->setManualArg(base64_encode(json_encode($params)));
         $cl->execute();
-        die($cl->output);
+        $o = trim($cl->output);
+        if (file_exists($o)) {
+            return $o;
+        }
+        echo $cl->commande . " : " . $cl->output;
+        return false;
     }
 
     public function _getFile($page, $format = 'jpg', $resolution = 150, $withText = true, $withGraphics = true, $version = 'html', $force = false)
     {
         global $core;
-//        if ($core->user->utilisateur_id == 5) {
-//            return $this->_getFileFarm($page, $format, $resolution, $withText, $withGraphics, $version, $force);
-//        }
-
+        if ($core->user->utilisateur_id == 5) {
+            return $this->_getFileFarm($page, $format, $resolution, $withText, $withGraphics, $version, $force);
+        }
 
         if ($format === 'jpeg') {
             $format = 'jpg';