From: Vincent Vanwaelscappel Date: Thu, 18 Jan 2024 18:32:22 +0000 (+0100) Subject: wait #6642 @0.5 X-Git-Url: http://git.cubedesigners.com/?a=commitdiff_plain;h=8c9550e23b2c9cb4998cf6d1b50a4a306f327883;p=fluidbook-toolbox.git wait #6642 @0.5 --- diff --git a/app/Jobs/FluidbookDocumentFileProcess.php b/app/Jobs/FluidbookDocumentFileProcess.php index c74ee8f8c..6cee64b00 100644 --- a/app/Jobs/FluidbookDocumentFileProcess.php +++ b/app/Jobs/FluidbookDocumentFileProcess.php @@ -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) diff --git a/app/Models/FluidbookDocument.php b/app/Models/FluidbookDocument.php index 83fe3a0bb..232324041 100644 --- a/app/Models/FluidbookDocument.php +++ b/app/Models/FluidbookDocument.php @@ -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;