]> _ Git - fluidbook-toolbox.git/commitdiff
wip #6150 @0.25
authorVincent Vanwaelscappel <vincent@cubedesigners.com>
Thu, 20 Jul 2023 10:43:47 +0000 (12:43 +0200)
committerVincent Vanwaelscappel <vincent@cubedesigners.com>
Thu, 20 Jul 2023 10:43:47 +0000 (12:43 +0200)
app/Fluidbook/Farm.php

index de638b3183c4e200976ce76ee5caf4711912e7bf..1284f3063d4d4a5280341c8c7a1b070c0910e39c 100644 (file)
@@ -13,7 +13,7 @@ use Illuminate\Support\Facades\Log;
 class Farm
 {
 
-    protected static $_forceServer = false;
+    protected static $_forceServer = 'alphaville';
     protected static $_farmServers = [
         ['name' => 'alphaville', 'host' => 'fluidbook-processfarm', 'port' => 9000, 'weight' => 24, 'region' => 'UE'],
         ['name' => 'brazil', 'host' => 'brazil.cubedesigners.com', 'weight' => 2, 'region' => 'US'],
@@ -50,14 +50,6 @@ class Farm
 
     public static function pickOneServer()
     {
-        if (self::$_forceServer) {
-            foreach (self::$_farmServers as $farmServer) {
-                if ($farmServer['name'] === self::$_forceServer) {
-                    return $farmServer;
-                }
-            }
-        }
-
         $hat = [];
         $pingCache = self::_pingCache();
         if (!file_exists($pingCache)) {
@@ -69,6 +61,9 @@ class Farm
             if (!isset($pings[$k]) || !$pings[$k]) {
                 continue;
             }
+            if (self::$_forceServer && $farmServer['name'] === self::$_forceServer) {
+                return $farmServer;
+            }
             for ($i = 0; $i < $farmServer['weight']; $i++) {
                 $hat[] = $k;
             }
@@ -110,7 +105,7 @@ class Farm
         return self::_getFile($params);
     }
 
-    public static function getFileFromPDF($pdf, $page, $format, $resolution, $quality, $withText = true, $withGraphics = true, $version = 'html', $out = null, $force = false)
+    public static function getFileFromPDF($pdf, $page, $format, $resolution, $quality, $withText = true, $withGraphics = true, $version = 'html', $out = null, $force = false, $attemps = 3)
     {
         if (null === $out) {
             $hash = Files::hashFileAttributes($pdf);
@@ -140,8 +135,8 @@ class Farm
         $res = Cache::rememberForever($cachekey, function () use ($params) {
             return self::_getFile($params);
         });
-        if (!$res) {
-            Cache::forget($cachekey);
+        if ((!$res || !file_exists($res))) {
+            return self::getFileFromPDF($pdf, $page, $format, $resolution, $quality, $withText, $withGraphics, $version, $out, true, $attemps - 1);
         }
         return $res;
     }