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

index b8ea5135629bbfeff0e33a1ecf1a54bcc877b06c..befc7f62006454ddbfbaef7ed458075b99bf881f 100644 (file)
@@ -17,6 +17,7 @@
     "jaybizzle/crawler-detect": "^1.2",\r
     "ext-mbstring": "*",\r
     "ext-simplexml": "*",\r
-    "cubist/matomo": "dev-master"\r
+    "cubist/matomo": "dev-master",\r
+    "ext-curl": "*"\r
   }\r
 }\r
index afbcc212a5437967677dceeb46cba5d2ae8edda2..3d386a0fd3323bfc72b5756d7b64edc73870a6cc 100644 (file)
@@ -1558,6 +1558,9 @@ class wsMaintenance
 
         $daoBook = new wsDAOBook($core->con);
         $book = $daoBook->selectById($book_id, true);
+
+        require_once ROOT . "/inc/ws/Util/html5/master/class.ws.html5.compiler.php";
+
         $resolutions = wsHTML5Compiler::getBookResolutions($book);
         $format = $book->parametres->imageFormat;
 
@@ -1574,13 +1577,14 @@ class wsMaintenance
         if ($page == 'all') {
             $pages = range(1, $book->parametres->pages);
         } else {
-            $pages = [$page];
+            $pages = cubeArray::parseRange($page);
         }
 
         shuffle($pages);
 
         foreach ($pages as $page) {
             foreach ($files as $file) {
+                echo ($force ? '!' : '') . $page . "-" . implode(',' . $file) . "\n";
                 $book->getFile($page, $file[0], $file[1], $file[2], $file[3], $file[4], $force);
             }
         }
@@ -1593,18 +1597,40 @@ class wsMaintenance
         global $core;
 
         $book_id = $args[0];
+        $force = isset($args[1]) && $args[1] != '0';
 
         $dao = new wsDAOBook($core->con);
         $book = $dao->selectById($book_id);
 
-        $url = 'https://workshop.fluidbook.com/maintenance/processPage/' . $book_id . '/all/0';
-        $ctx = stream_context_create(["http" => ["timeout" => 1]]);
-        $it = 2 * max(4, min(12, ceil(count($book->parametres->pages) / 20)));
-        for ($i = 0; $i < $it; $i++) {
-            file_get_contents($url, 0, $ctx);
+        $count = $book->parametres->pages;
+        $allPages = range(1, $count);
+
+        $it = 2 * max(4, min(12, ceil($count / 20)));
+
+        shuffle($allPages);
+
+        $portions = array_chunk($allPages, ceil($count / $it));
+
+        foreach ($portions as $p) {
+            $url = 'https://workshop.fluidbook.com/maintenance/processPage/' . $book_id . '/' . implode(',', $p) . '/' . ($force ? '1' : '0');
+            echo $url . "\n";
+            self::timeoutRequest($url . '?PHPSESSID=' . session_id(), 1);
         }
     }
 
+    public static function timeoutRequest($url, $timeout)
+    {
+        $ch = curl_init();
+
+        curl_setopt($ch, CURLOPT_URL, $url);
+        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
+        curl_setopt($ch, CURLOPT_TIMEOUT, $timeout);
+        curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
+
+        curl_exec($ch);
+        curl_close($ch);
+    }
+
 
     public static function getAdditionalSettingsMap(): array
     {
@@ -1861,14 +1887,15 @@ class wsMaintenance
         }
 
         foreach ($servers as $id => $farmer) {
+            echo '<h2>' . $farmer['name'] . ' (' . $id . ')</h2>';
             if (isset($pings[$id]) && !$pings[$id]) {
                 // If ping failed recently, we wait a bit before trying again.
-                if (rand(0, 9) === 5) {
+                if (rand(0, 9) != 5) {
+                    echo '<p>Skipped, will try again soon</p>';
                     continue;
                 }
-                break;
             }
-            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();
index d04e2c5baac272f669606b34e550f7c2a78fba92..cf69cdad80d06fc5b26a35dc26f97ad987eea8d4 100644 (file)
@@ -127,10 +127,9 @@ class wsBook extends cubeMetier
         return $book->getAssetDir($sub);\r
     }\r
 \r
-    public static function precompileImages($book_id){\r
+    public static function precompileImages($book_id)\r
+    {\r
         // Begin to generate files async\r
-        $url = 'https://workshop.fluidbook.com/maintenance/processBookPages/' . $book_id;\r
-        $ctx = stream_context_create(["http" => ["timeout" => 1]]);\r
-        file_get_contents($url, 0, $ctx);\r
+        wsMaintenance::timeoutRequest('https://workshop.fluidbook.com/maintenance/processBookPages/' . $book_id . '?PHPSESSID=' . session_id(), 1);\r
     }\r
 }
\ No newline at end of file
index de822dbf39c32bbdae99cfbfc7be1b423a151c3e..8c779b73b148f5d55fd64efab6123e03baa05766 100644 (file)
@@ -56,13 +56,13 @@ class wsDocument extends cubeMetier
     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' => 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],
+        ['name' => 'elephantman', 'host' => 'elephantman.cubedesigners.com', 'port' => 22822, 'weight' => 1],
+        ['name' => 'fastandfurious', 'host' => 'fastandfurious.cubedesigners.com', 'port' => 22822, 'weight' => 1],
+        ['name' => 'vmparis', 'host' => 'paris.cubedesigners.com', 'port' => 22922, 'weight' => 2],
+        ['name' => 'vincent', 'host' => 'paris.cubedesigners.com', 'port' => 22923, 'weight' => 1],
+        ['name' => 'godzilla', 'host' => 'godzilla.cubedesigners.com', 'weight' => 3],
+        ['name' => 'dracula', 'host' => 'dracula.cubedesigners.com', 'weight' => 3],
+        ['name' => 'her', 'host' => 'her.cubedesigners.com', 'weight' => 4],
     ];
 
     protected static $resolution2multiply = array(72 => 2, 100 => 2, 150 => 3, 200 => 3, 300 => 3, 450 => 4, 600 => 5);
@@ -476,6 +476,7 @@ class wsDocument extends cubeMetier
 
     public function _getFileFarm($page, $format = 'jpg', $resolution = 150, $withText = true, $withGraphics = true, $version = 'html', $force = false)
     {
+        $start = microtime(true);
         $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()];
@@ -487,12 +488,21 @@ class wsDocument extends cubeMetier
         if (preg_match('|/data1/extranet/www/[^\s]+|', $o, $matches)) {
             $o = $matches[0];
         }
+
         if (file_exists($o)) {
-            return $o;
+            $res = $o;
         } else {
             echo $cl->output;
+            $res = false;
         }
-        return false;
+        $time = round(microtime(true) - $start, 4);
+        $log = '[' . $farmer['name'] . ']' . "\t\t\t\t" . $time . "\t\t\t\t$page|$format|$resolution|$withText|$withGraphics|$version\t\t\t\t$res\t\t\t\t$cl->output\n";
+
+        $fp = fopen(WS_DOCS . '/' . $this->document_id . '/farm.log', 'a+');
+        fwrite($fp, $log);
+        fclose($fp);
+
+        return $res;
     }
 
     public function _getFile($page, $format = 'jpg', $resolution = 150, $withText = true, $withGraphics = true, $version = 'html', $force = false)