From: Vincent Vanwaelscappel Date: Tue, 13 Feb 2024 17:53:21 +0000 (+0100) Subject: wip #6711 @0.5 X-Git-Url: http://git.cubedesigners.com/?a=commitdiff_plain;h=f81d00b4d427602ead42efe2ef90e66be1145156;p=fluidbook-toolbox.git wip #6711 @0.5 --- diff --git a/app/Fluidbook/Packager/Packager.php b/app/Fluidbook/Packager/Packager.php index 76b3f374c..ba9ae08d8 100644 --- a/app/Fluidbook/Packager/Packager.php +++ b/app/Fluidbook/Packager/Packager.php @@ -10,6 +10,8 @@ use Cubist\Util\Files\Files; use Cubist\Util\PHP; use Cubist\Util\Text; use Exception; +use Illuminate\Contracts\Cache\Lock; +use Illuminate\Support\Facades\Cache; class Packager extends \App\Jobs\Base { @@ -40,6 +42,11 @@ class Packager extends \App\Jobs\Base public $downloadExt = 'zip'; + public $type = "unset"; + + /** @var Lock */ + protected $lock; + /** * @var string */ @@ -108,11 +115,13 @@ class Packager extends \App\Jobs\Base public function __construct($book_id, $vdir = null, $options = []) { - $this->_time = time(); $this->_clean = (null === $vdir); $this->book_id = $book_id; + + $this->lock = Cache::lock('fluidbook_package_' . $this->type . '_' . $this->book_id, 1800); + $this->book = FluidbookPublication::find($book_id); $this->vdir = $vdir; @@ -151,8 +160,14 @@ class Packager extends \App\Jobs\Base public function handle() { - PHP::neverStop(); - $this->makePackage($this->zipPackage); + if ($this->lock->block(1800)) { + try { + PHP::neverStop(); + $this->makePackage($this->zipPackage); + } finally { + $this->lock?->release(); + } + } } protected function packager_path($path = '') @@ -369,4 +384,13 @@ class Packager extends \App\Jobs\Base { $this->_finalURL = $finalURL; } + + public function __destruct() + { + try { + $this->lock?->release(); + } catch (\Exception $e) { + + } + } }