Skip to content

Commit

Permalink
start write new job for EduGain (not ready script run part)
Browse files Browse the repository at this point in the history
  • Loading branch information
temaotl committed Jul 13, 2024
1 parent 0094a51 commit 9e99685
Show file tree
Hide file tree
Showing 3 changed files with 72 additions and 2 deletions.
70 changes: 70 additions & 0 deletions app/Jobs/EduGainAddEntity.php
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();
}
}



}
}
2 changes: 1 addition & 1 deletion app/Jobs/FolderAddEntity.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public function handle(): void
$lock = Cache::lock($lockKey, 61);

try {
$lock->block(120);
$lock->block(61);
EntityFacade::saveMetadataToFederationFolder($this->entity->id, $fedId->federation_id);


Expand Down
2 changes: 1 addition & 1 deletion app/Jobs/RunMdaScript.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public function handle(): void

$filterArray = explode(', ', $this->federation->filters);
$scriptPath = config('storageCfg.mdaScript');
$command = 'sh '.config('storageCfg.mdaScript');


$realScriptPath = realpath($scriptPath);

Expand Down

0 comments on commit 9e99685

Please sign in to comment.