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
{
public $downloadExt = 'zip';
+ public $type = "unset";
+
+ /** @var Lock */
+ protected $lock;
+
/**
* @var string
*/
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;
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 = '')
{
$this->_finalURL = $finalURL;
}
+
+ public function __destruct()
+ {
+ try {
+ $this->lock?->release();
+ } catch (\Exception $e) {
+
+ }
+ }
}