70 lines
1.9 KiB
PHP
70 lines
1.9 KiB
PHP
<?php
|
|
|
|
namespace App\Jobs;
|
|
|
|
use App\Models\Project;
|
|
use App\Models\ProjectReport;
|
|
use Illuminate\Bus\Queueable;
|
|
use Illuminate\Contracts\Queue\ShouldBeUnique;
|
|
use Illuminate\Contracts\Queue\ShouldQueue;
|
|
use Illuminate\Foundation\Bus\Dispatchable;
|
|
use Illuminate\Queue\InteractsWithQueue;
|
|
use Illuminate\Queue\SerializesModels;
|
|
use Symfony\Component\Process\Process;
|
|
|
|
class ProjectMosiacGeneratorJob implements ShouldQueue
|
|
{
|
|
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
|
|
|
|
|
|
public $year;
|
|
public $week;
|
|
public Project $project;
|
|
/**
|
|
* Create a new job instance.
|
|
*/
|
|
public function __construct(Project $project, $year, $week)
|
|
{
|
|
$this->year = $year;
|
|
$this->week = $week;
|
|
//
|
|
}
|
|
|
|
/**
|
|
* Execute the job.
|
|
*/
|
|
public function handle(): void
|
|
{
|
|
$weeksAgo = ProjectReport::weeksAgoForYearAndWeek($this->year, $this->week);
|
|
|
|
$projectFolder = base_path('../');
|
|
|
|
$command = [
|
|
sprintf('%sbuild_mosaic.sh', $projectFolder),
|
|
sprintf('--weeks_ago=%s', $weeksAgo),
|
|
];
|
|
|
|
|
|
$process = new Process($command);
|
|
$process->setTimeout(120);
|
|
$currentPath = '/usr/gnu/bin:/usr/local/bin:/bin:/usr/bin/Users/mfolkerts/anaconda3/bin:/Library/Apple/usr/bin';
|
|
|
|
$process->setEnv(['PATH' => $currentPath.':/usr/local/Cellar/pandoc/3.1.8/bin/pandoc']);
|
|
// $process->setTimeout(36000); // stel een geschikte timeout in
|
|
$process->start();
|
|
try {
|
|
$myOutput = [];
|
|
$process->wait(function ($type, $buffer) use (&$myOutput) {
|
|
// $this->stream(to: 'processOutput', content: $buffer);
|
|
$myOutput[] = $buffer;
|
|
logger($buffer);
|
|
});
|
|
$this->processOutput = collect($myOutput)->join('\n');
|
|
|
|
} catch (ProcessFailedException $exception) {
|
|
echo $exception->getMessage();
|
|
|
|
}
|
|
}
|
|
}
|