Skip to content

Commit

Permalink
write DeleteFederation.php job not add to observer and not tested
Browse files Browse the repository at this point in the history
  • Loading branch information
temaotl committed Jul 25, 2024
1 parent 9a84bb5 commit c5f2ada
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 3 deletions.
4 changes: 2 additions & 2 deletions app/Console/Commands/ValidateMetaConsole.php
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,8 @@ private function runMDA(Federation $federation)

public function handle()
{
$federation = Federation::where('id', 1)->first();
$this->runMDA($federation);
/* $federation = Federation::where('id', 1)->first();
$this->runMDA($federation);*/

// $this->fixEntities();
// $this->doc();
Expand Down
58 changes: 58 additions & 0 deletions app/Jobs/DeleteFederation.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
<?php

namespace App\Jobs;

use App\Models\Federation;
use App\Services\FederationService;
use App\Traits\HandlesJobsFailuresTrait;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\SerializesModels;
use Illuminate\Support\Facades\Cache;
use Illuminate\Support\Facades\Storage;
use Mockery\Exception;

class DeleteFederation implements ShouldQueue
{
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;

/**
* trait with failure function
*/
use HandlesJobsFailuresTrait;

public Federation $federation;

/**
* Create a new job instance.
*/
public function __construct(Federation $federation)
{
$this->federation = $federation;
}

/**
* Execute the job.
*/
public function handle(): void
{
$diskName = config('storageCfg.name');
$pathToDirectory = Storage::disk($diskName)->path($this->federation->name);
$lockKey = 'directory-'.md5($pathToDirectory).'-lock';
$lock = Cache::lock($lockKey, 61);
try {
$lock->block(61);
FederationService::DeleteFederationFolder($this->federation->name);

} catch (Exception $e) {
$this->fail($e);
} finally {
if ($lock->isOwnedByCurrentProcess()) {
$lock->release();
}
}

}
}
1 change: 0 additions & 1 deletion app/Jobs/FolderDeleteEntity.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
class FolderDeleteEntity implements ShouldQueue
{
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
use HandlesJobsFailuresTrait;

/**
* trait with failure function
Expand Down
6 changes: 6 additions & 0 deletions app/Services/FederationService.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,10 @@ public static function createFoldersToAllFederation(): void
}
}
}

public static function DeleteFederationFolder(string $name): void
{
$diskName = config('storageCfg.name');
Storage::disk($diskName)->deleteDirectory($name);
}
}

0 comments on commit c5f2ada

Please sign in to comment.