-
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.
start write new job for EduGain (not ready script run part)
- Loading branch information
Showing
3 changed files
with
72 additions
and
2 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
<?php | ||
|
||
namespace App\Jobs; | ||
|
||
use App\Facades\EntityFacade; | ||
use App\Models\Entity; | ||
use App\Notifications\EntityStateChanged; | ||
use App\Notifications\EntityUpdated; | ||
use App\Services\NotificationService; | ||
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 EduGainAddEntity implements ShouldQueue | ||
{ | ||
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels; | ||
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::saveMetadataToFederationFolder($this->entity->id,$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