Skip to content

Commit

Permalink
added parse job
Browse files Browse the repository at this point in the history
  • Loading branch information
skarampatakis committed Apr 11, 2018
1 parent 3542148 commit 0e66cf7
Show file tree
Hide file tree
Showing 2 changed files with 79 additions and 32 deletions.
36 changes: 4 additions & 32 deletions app/Http/Controllers/FileController.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,6 @@ public function update()
$file->save();

return redirect()->route('mygraphs')->with('notification', 'File updated!!!');


}

public function destroy(File $file)
Expand All @@ -88,34 +86,8 @@ public function download(Request $request, File $file){
}

public function parse(File $file)
{
/*
* Read the graph
*/
try{
if($file->filetype != 'ntriples'){
$this->convert($file);
$file->cacheGraph();
}
else{
$file->cacheGraph();
}
return redirect()->route('mygraphs')->with('notification', 'Graph Parsed!!!');

} catch (\Exception $ex) {
$file->parsed = false;
$file->save();
error_log($ex);
return redirect()->route('mygraphs')->with('error', 'Failed to parse the graph. Please check the logs.' . $ex);
}
}

public function convert(File $file){
$command = 'rapper -i ' . $file->filetype . ' -o ntriples ' . $file->resource->path() . ' > ' . $file->resource->path(). '.nt';
$out = [];
logger($command);
exec( $command, $out);
logger(var_dump($out));
return;
}
{
dispatch(new \App\Jobs\Parse($file, auth()->user()));
return redirect()->back()->with('notification', 'Parsing Job Dispatched, check your logs.');
}
}
75 changes: 75 additions & 0 deletions app/Jobs/Parse.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
<?php

namespace App\Jobs;

use App\File;
use App\User;
use Illuminate\Bus\Queueable;
use Illuminate\Queue\SerializesModels;
use Symfony\Component\Process\Process;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
use Symfony\Component\Process\Exception\ProcessFailedException;

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

protected $file, $user;

/**
* Create a new job instance.
*
* @return void
*/
public function __construct(File $file, User $user)
{
$this->file = $file;
$this->user = $user;
}

/**
* Execute the job.
*
* @return void
*/
public function handle()
{
$this->parse($this->file);
}

public function parse(File $file)
{
/*
* Read the graph
*/
try{
if($file->filetype != 'ntriples'){
$this->reserialize($file);
}
$file->cacheGraph();
} catch (\Exception $ex) {
$file->parsed = false;
$file->save();
error_log($ex);
}
}

public function reserialize(File $file){
$command = [
'rapper',
'-i ',
$file->filetype,
'-o',
'ntriples',
$file->resource->path(),
'>',
$file->resource->path(). '.nt'
];

$process = new Process($command);
$process->run();
return;
}
}

0 comments on commit 0e66cf7

Please sign in to comment.