Skip to content

Commit

Permalink
uncommented notification and make better RunMdaScript
Browse files Browse the repository at this point in the history
  • Loading branch information
temaotl committed Jul 13, 2024
1 parent eb4e015 commit d099eb7
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 7 deletions.
6 changes: 3 additions & 3 deletions app/Jobs/FolderAddEntity.php
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion app/Jobs/FolderDeleteEntity.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
11 changes: 10 additions & 1 deletion app/Jobs/RunMdaScript.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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()
];

}
}
3 changes: 1 addition & 2 deletions app/Providers/AppServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,11 @@ public function boot()
// Mail::alwaysTo('[email protected]');
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);
});*/

Expand Down

0 comments on commit d099eb7

Please sign in to comment.