From 85ee4724ee4b15b06f77db4f6f644e2ff0a69a44 Mon Sep 17 00:00:00 2001 From: guillaume91 Date: Wed, 19 Jun 2024 15:52:10 +0200 Subject: [PATCH] wip process --- .../app/Jobs/ProjectMosiacGeneratorJob.php | 49 +++++++++++++++---- .../app/Rules/AllMosaicsPresentRule.php | 6 +-- 2 files changed, 42 insertions(+), 13 deletions(-) diff --git a/laravel_app/app/Jobs/ProjectMosiacGeneratorJob.php b/laravel_app/app/Jobs/ProjectMosiacGeneratorJob.php index 0b1507b..26a15ce 100644 --- a/laravel_app/app/Jobs/ProjectMosiacGeneratorJob.php +++ b/laravel_app/app/Jobs/ProjectMosiacGeneratorJob.php @@ -2,22 +2,19 @@ namespace App\Jobs; -use App\Enums\Status; -use App\Livewire\Projects\Tabs\Mosaic; use App\Models\Project; -use App\Models\ProjectDownload; use App\Models\ProjectMosaic; -use App\Models\ProjectReport; use Carbon\Carbon; 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\Process\Exceptions\ProcessFailedException; +use Illuminate\Process\Exceptions\ProcessTimedOutException; use Illuminate\Queue\InteractsWithQueue; use Illuminate\Queue\SerializesModels; use Symfony\Component\Process\Process; +use Illuminate\Support\Facades\Process as ProcessNew; /** * @@ -41,9 +38,9 @@ public function __construct(ProjectMosaic $mosaic) /** * Execute the job. */ - public function handle(): void + public function handleNew(): void { - $weeksAgo = ProjectReport::weeksAgoForYearAndWeek($this->mosaic->year, $this->mosaic->week); + //$weeksAgo = ProjectReport::weeksAgoForYearAndWeek($this->mosaic->year, $this->mosaic->week); //TODO change to end_date and offset @@ -51,7 +48,8 @@ public function handle(): void $command = [ sprintf('%sbuild_mosaic.sh', $projectFolder), - sprintf('--weeks_ago=%s', $weeksAgo), + sprintf('--end_date=%s', $this->mosaic->end_date), + sprintf('--offset=%s', $this->mosaic->offset), sprintf('--data_dir=%s', $this->mosaic->project->download_path), ]; @@ -62,7 +60,6 @@ public function handle(): void $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) { @@ -80,6 +77,40 @@ public function handle(): void } } + /** + * Execute the job. + */ + public function handle(): void + { + //$weeksAgo = ProjectReport::weeksAgoForYearAndWeek($this->mosaic->year, $this->mosaic->week); + + + $projectFolder = base_path('../'); + + $command = [ + sprintf('%sbuild_mosaic.sh', $projectFolder), + sprintf('--end_date=%s', $this->mosaic->end_date), + sprintf('--offset=%s', $this->mosaic->offset), + sprintf('--data_dir=%s', $this->mosaic->project->download_path), + ]; + $currentPath = '/usr/bin:/usr/gnu/bin:/usr/local/bin:/bin:/usr/bin/Users/mfolkerts/anaconda3/bin:/Library/Apple/usr/bin'; + + try{ + $process = ProcessNew::timeout(220) + ->env(['PATH' => $currentPath . ':/usr/local/Cellar/pandoc/3.1.8/bin/pandoc']) + ->start($command, function (string $type, string $output ) { + logger($output); + }); + $results = $process->wait(); + if($results->successful()){ + $this->mosaic->setStatusSuccess(); + } + }catch(\RuntimeException|ProcessTimedOutException|ProcessFailedException $e){ + echo $e->getMessage(); + $this->mosaic->setStatusFailed(); + } + } + // public static function handleFor(Project $project, $year, $startWeekNumber) // { // logger("ProjectMosiacGeneratorJob::handleFor(week $startWeekNumber, year $year)"); diff --git a/laravel_app/app/Rules/AllMosaicsPresentRule.php b/laravel_app/app/Rules/AllMosaicsPresentRule.php index 7a7e3d0..efbfa3f 100644 --- a/laravel_app/app/Rules/AllMosaicsPresentRule.php +++ b/laravel_app/app/Rules/AllMosaicsPresentRule.php @@ -5,6 +5,7 @@ use Illuminate\Contracts\Validation\Rule; use App\Models\Project; use App\Models\ProjectReport; +use Carbon\Carbon; class AllMosaicsPresentRule implements Rule { @@ -27,10 +28,7 @@ public function passes($attribute, $value) return false; } - return $project->allMosaicsPresent( - // TODO change with end_date. - $value['end_date'] - ); + return $project->allMosaicsPresent(new Carbon($value['end_date'])); } catch (\Exception $e) { $this->errorMessage = $e->getMessage(); return false;