From d099eb7a4c5c1096389f90365f6e9641f99e1c05 Mon Sep 17 00:00:00 2001 From: Artem Otliaguzov Date: Sat, 13 Jul 2024 10:11:37 +0200 Subject: [PATCH] uncommented notification and make better RunMdaScript --- app/Jobs/FolderAddEntity.php | 6 +++--- app/Jobs/FolderDeleteEntity.php | 2 +- app/Jobs/RunMdaScript.php | 11 ++++++++++- app/Providers/AppServiceProvider.php | 3 +-- 4 files changed, 15 insertions(+), 7 deletions(-) diff --git a/app/Jobs/FolderAddEntity.php b/app/Jobs/FolderAddEntity.php index f5b4c89..fee9f4f 100644 --- a/app/Jobs/FolderAddEntity.php +++ b/app/Jobs/FolderAddEntity.php @@ -65,18 +65,18 @@ public function handle(): void } $pathToDirectory = Storage::disk($diskName)->path($federation->name); $lockKey = 'directory-'.md5($pathToDirectory).'-lock'; - $lock = Cache::lock($lockKey, 120); + $lock = Cache::lock($lockKey, 61); try { $lock->block(120); EntityFacade::saveMetadataToFederationFolder($this->entity->id, $fedId->federation_id); -/* if ($this->entity->wasRecentlyCreated) { + if ($this->entity->wasRecentlyCreated) { NotificationService::sendEntityNotification($this->entity,EntityUpdated::class); } elseif ($this->entity->wasChanged('deleted_at') && is_null($this->entity->deleted_at)) { NotificationService::sendEntityNotification($this->entity,EntityStateChanged::class); - }*/ + } RunMdaScript::dispatch($federation, $lock->owner()); } catch (Exception $e) { diff --git a/app/Jobs/FolderDeleteEntity.php b/app/Jobs/FolderDeleteEntity.php index 34540cf..e3c6731 100644 --- a/app/Jobs/FolderDeleteEntity.php +++ b/app/Jobs/FolderDeleteEntity.php @@ -53,7 +53,7 @@ public function handle(): void } $pathToDirectory = Storage::disk($diskName)->path($federation->name); $lockKey = 'directory-'.md5($pathToDirectory).'-lock'; - $lock = Cache::lock($lockKey, 120); + $lock = Cache::lock($lockKey, 61); try { $lock->block(120); EntityFacade::deleteEntityMetadataFromFolder($entity->file, $federation->xml_id); diff --git a/app/Jobs/RunMdaScript.php b/app/Jobs/RunMdaScript.php index 4aae30e..96073f3 100644 --- a/app/Jobs/RunMdaScript.php +++ b/app/Jobs/RunMdaScript.php @@ -8,6 +8,7 @@ use Illuminate\Foundation\Bus\Dispatchable; use Illuminate\Queue\InteractsWithQueue; use Illuminate\Queue\Middleware\RateLimited; +use Illuminate\Queue\Middleware\WithoutOverlapping; use Illuminate\Queue\SerializesModels; use Illuminate\Support\Facades\Cache; use Illuminate\Support\Facades\Log; @@ -74,6 +75,14 @@ public function handle(): void */ public function middleware(): array { - return [new RateLimited('mda-run-limit')]; + $diskName = config('storageCfg.name'); + $pathToDirectory = Storage::disk($diskName)->path($this->federation->name); + $lockKey = 'directory-' . md5($pathToDirectory) . '-lock'; + + return [ + new RateLimited('mda-run-limit'), + (new WithoutOverlapping($lockKey))->dontRelease() + ]; + } } diff --git a/app/Providers/AppServiceProvider.php b/app/Providers/AppServiceProvider.php index e7a30f4..58e39d6 100644 --- a/app/Providers/AppServiceProvider.php +++ b/app/Providers/AppServiceProvider.php @@ -33,12 +33,11 @@ public function boot() // Mail::alwaysTo('foo@example.org'); Model::preventLazyLoading(); } - +//TODO comment this for testing part /* RateLimiter::for('mda-run-limit', function (RunMdaScript $job) { $diskName = config('storageCfg.name'); $pathToDirectory = Storage::disk($diskName)->path($job->federation->name); $lockKey = 'directory-'.md5($pathToDirectory).'-lock'; - return Limit::perMinute(1)->by($lockKey); });*/