SmartCane/laravel_app/app/Jobs/ProjectReportGeneratorJob.php
2024-01-30 16:06:55 +01:00

74 lines
2.3 KiB
PHP

<?php
namespace App\Jobs;
use App\Models\ProjectReport;
use Illuminate\Bus\Batchable;
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 ProjectReportGeneratorJob implements ShouldQueue
{
use Batchable, Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
public $timeout = 220;
private ProjectReport $projectReport;
/**
* Create a new job instance.
*/
public function __construct(ProjectReport $projectReport)
{
$this->projectReport = $projectReport;
//
}
/**
* Execute the job.
*/
public function handle(): void
{
logger('in handle');
$this->projectReport->weeksAgo();
$projectFolder = base_path('../');
$command = [
sprintf('%sbuild_report.sh', $projectFolder),
sprintf('--filename=%s', $this->projectReport->getFullPathName()),
sprintf('--weeks_ago=%s', $this->projectReport->weeksAgo()),
sprintf('--report_date=%s', $this->projectReport->getReportDate()),
];
// Convert commands array to a single string
$process = new Process($command);
$process->setTimeout(220);
$currentPath = '/usr/bin:/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');
$this->projectReport->setStatusSuccess();
} catch (ProcessFailedException $exception) {
echo $exception->getMessage();
$this->projectReport->setStatusFailed();
}
//
}
}