-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
write DeleteFederation.php job not add to observer and not tested
- Loading branch information
Showing
4 changed files
with
66 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters