Skip to content

Commit

Permalink
add run script to EduGain jobs
Browse files Browse the repository at this point in the history
  • Loading branch information
temaotl committed Jul 13, 2024
1 parent e612537 commit 1a79a55
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 2 deletions.
2 changes: 1 addition & 1 deletion app/Jobs/EduGainAddEntity.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@ public function handle(): void
EntityFacade::saveEntityMetadataToFolder($this->entity->id,$folderName);

//TODO write custom function to run special MDA script (ask about this)
EduGainRunMdaScript::dispatch($lock->owner());

// RunMdaScript::dispatch($federation, $lock->owner());
} catch (Exception $e) {
Log::error($e->getMessage());
} finally {
Expand Down
2 changes: 1 addition & 1 deletion app/Jobs/EduGainDeleteEntity.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public function handle(): void

//TODO write custom function to run special MDA script (ask about this)

// RunMdaScript::dispatch($federation, $lock->owner());
EduGainRunMdaScript::dispatch($lock->owner());
} catch (Exception $e) {
Log::error($e->getMessage());
} finally {
Expand Down
61 changes: 61 additions & 0 deletions app/Jobs/EduGainRunMdaScript.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
<?php

namespace App\Jobs;

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;
use Mockery\Exception;

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

public string $owner;

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

/**
* Execute the job.
*/
public function handle(): void
{
$diskName = config('storageCfg.name');
$folderName = config('storageCfg.edu2edugain');

$pathToDirectory = Storage::disk($diskName)->path($folderName);
$lockKey = 'directory-'.md5($pathToDirectory).'-lock';
$scriptPath = config('storageCfg.mdaScript');
$realScriptPath = realpath($scriptPath);

try {
$file = escapeshellarg($folderName).'.xml';
$pipeline = 'main';
$command = 'sh '.escapeshellarg($realScriptPath).' '.$file.' '.$pipeline;

$res = shell_exec($command);
dump($res);

} catch (Exception $e) {
Log::error($e->getMessage());
} finally {
Cache::restoreLock($lockKey, $this->owner)->release();

}




}
}

0 comments on commit 1a79a55

Please sign in to comment.