-
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 working EduToEdugain jobs but without mda script
- Loading branch information
Showing
6 changed files
with
100 additions
and
8 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,69 @@ | ||
<?php | ||
|
||
namespace App\Jobs; | ||
|
||
use App\Facades\EntityFacade; | ||
use App\Models\Entity; | ||
use App\Traits\HandlesJobsFailuresTrait; | ||
use Exception; | ||
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\Log; | ||
use Illuminate\Support\Facades\Storage; | ||
|
||
class EduGainDeleteEntity implements ShouldQueue | ||
{ | ||
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels; | ||
|
||
/** | ||
* trait with failure function | ||
*/ | ||
use HandlesJobsFailuresTrait; | ||
|
||
public Entity $entity; | ||
|
||
/** | ||
* Create a new job instance. | ||
*/ | ||
public function __construct(Entity $entity) | ||
{ | ||
$this->entity = $entity; | ||
} | ||
|
||
/** | ||
* Execute the job. | ||
*/ | ||
public function handle(): void | ||
{ | ||
$diskName = config('storageCfg.name'); | ||
$folderName = config('storageCfg.edu2edugain'); | ||
try { | ||
if (! Storage::disk($diskName)->exists($folderName)) { | ||
throw new Exception("No $folderName in $diskName"); | ||
} | ||
} catch (Exception $e) { | ||
$this->fail($e); | ||
} | ||
$pathToDirectory = Storage::disk($diskName)->path($folderName); | ||
$lockKey = 'directory-'.md5($pathToDirectory).'-lock'; | ||
$lock = Cache::lock($lockKey, 61); | ||
try { | ||
$lock->block(61); | ||
EntityFacade::deleteEntityMetadataFromFolder($this->entity->file,$folderName); | ||
|
||
//TODO write custom function to run special MDA script (ask about this) | ||
|
||
// RunMdaScript::dispatch($federation, $lock->owner()); | ||
} catch (Exception $e) { | ||
Log::error($e->getMessage()); | ||
} 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
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