]> _ Git - fluidbook-toolbox.git/commitdiff
wait #6642 @0.5
authorVincent Vanwaelscappel <vincent@cubedesigners.com>
Thu, 18 Jan 2024 18:32:22 +0000 (19:32 +0100)
committerVincent Vanwaelscappel <vincent@cubedesigners.com>
Thu, 18 Jan 2024 18:32:22 +0000 (19:32 +0100)
app/Jobs/FluidbookDocumentFileProcess.php
app/Models/FluidbookDocument.php

index c74ee8f8cd1f5d557056ab8cb23fdcc3bf2fecf1..6cee64b0022b31d7c6c4868f3da2234a4527e7cc 100644 (file)
@@ -3,6 +3,7 @@
 namespace App\Jobs;
 
 use App\Models\FluidbookDocument;
+use Illuminate\Support\Facades\Cache;
 use Illuminate\Support\Facades\Log;
 
 class FluidbookDocumentFileProcess extends Base
@@ -19,8 +20,6 @@ class FluidbookDocumentFileProcess extends Base
     protected $forceCheck;
     protected $forceProcess;
 
-    protected $finish = false;
-
     protected $path = "";
 
     protected $log = '';
@@ -44,22 +43,32 @@ class FluidbookDocumentFileProcess extends Base
 
     public function handle()
     {
-        $this->finish = false;
         try {
             echo $this->document->getFile($this->page, $this->format, $this->resolution, $this->quality, $this->withText, $this->withGraphics, $this->version, $this->forceCheck, $this->forceProcess) . "\n";
         } catch (\Exception $e) {
             Log::warning($e->getMessage());
             $this->log = $e->getMessage();
         }
-        $this->finish = true;
+        $this->setFinish();
+    }
+
+    public function setFinish($finish = true)
+    {
+        Cache::put('job_' . $this->path, $finish, 300);
+    }
+
+
+    public function isFinish()
+    {
+        return Cache::get('job_' . $this->path, false);
     }
 
     /**
      * @return boolean
      */
-    public function isDone($forceCheck = false, $checkFile = true)
+    public function isDone($forceCheck = false)
     {
-        return $this->finish || ($checkFile && $this->isOK($forceCheck));
+        return $this->isFinish() || $this->isOK($forceCheck);
     }
 
     public function isOK($forceCheck = false)
index 83fe3a0bb4124c7daabc821c214735a7e764ff10..232324041f5c7e9baefac4204d6ed6c9b4d0af2e 100644 (file)
@@ -104,8 +104,6 @@ class FluidbookDocument extends ToolboxModel
             ['svg', 150, true, false, 'html'],
         ];
 
-        Log::debug('Sync ? ' . $sync);
-
         $nbfiles = count($files);
         for ($i = 1; $i <= $this->pages; $i++) {
             foreach ($files as $file) {
@@ -118,21 +116,21 @@ class FluidbookDocument extends ToolboxModel
 
                 $jobs[] = $job;
                 if ($sync) {
-                    $this->_checkJobs($uploadID, $jobs, $nbfiles, true);
+                    $this->_checkJobs($uploadID, $jobs, $nbfiles);
                 }
             }
 
-            if (!$sync && $i % 4 === 0) {
-                $this->_checkJobs($uploadID, $jobs, $nbfiles, false);
+            if (!$sync) {
+                $this->_checkJobs($uploadID, $jobs, $nbfiles);
             }
 
         }
 
         while (true) {
-            if ($this->_checkJobs($uploadID, $jobs, $nbfiles, true) === 1) {
+            if ($this->_checkJobs($uploadID, $jobs, $nbfiles) === 1) {
                 return;
             }
-            usleep(0.25 * 1000000);
+            usleep(5 * 1000000);
         }
     }
 
@@ -156,14 +154,14 @@ class FluidbookDocument extends ToolboxModel
         Farm::extractLinks($this->getPDFSource(), $this->path());
     }
 
-    protected function _checkJobs($uploadID, $jobs, $nbfiles, $checkFile = true)
+    protected function _checkJobs($uploadID, $jobs, $nbfiles)
     {
         $this->checkInfos();
         $nbjobs = $nbfiles * $this->pages;
         $done = 0;
         foreach ($jobs as $job) {
             /** @var $job FluidbookDocumentFileProcess */
-            if ($job->isDone(false, $checkFile)) {
+            if ($job->isDone()) {
                 $done++;
             }
         }
@@ -180,7 +178,6 @@ class FluidbookDocument extends ToolboxModel
     public function checkInfos($force = false)
     {
         if ($force || null === $this->pdf_data) {
-            Log::debug('check document infos');
             $infos = $this->_getInfos();
 
             $this->pages = $infos->pages;