mosaic = $mosaic; } /** * Execute the job. */ /** * Execute the job. */ public function handle(): void { $projectFolder = base_path('../'); $project = $this->mosaic->project; $command = [ sprintf('%sbuild_mosaic.sh', $projectFolder), sprintf('--end_date=%s', $this->mosaic->end_date->format('Y-m-d')), sprintf('--offset=%s', $this->mosaic->offset), sprintf('--data_dir=%s', $this->mosaic->project->download_path), sprintf('--file_name_tif=%s', basename($this->mosaic->path)), ]; ProjectLogger::log($project, 'command:'. print_r($command, true)); $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) use ($project) { ProjectLogger::log($project, $output); $this->throwIfOutputContainsError($output); }); $results = $process->wait(); if ($results->successful()) { $this->mosaic->setStatusSuccess(); } } catch (\RuntimeException|ProcessTimedOutException|ProcessFailedException $e) { ProjectLogger::log($project, $e->getMessage()); $this->mosaic->setStatusFailed(); } } /** * Check if the project has a mosaic for given period. */ public static function handleFor(Project $project, Carbon $endDate, int $offset): NullJob|ProjectMosiacGeneratorJob { $endDate = $endDate->clone(); ProjectLogger::log($project, "ProjectMosiacGeneratorJob::handleFor($endDate, $offset)"); if ($project->hasInvalidMosaicFor($endDate, $offset)) { ProjectLogger::log($project,"ProjecMosaicGeneratorJob::handleFor(end_date: $endDate, offset: $offset): InvalidMosaic."); return new NullJob(); } ProjectLogger::log($project, __CLASS__."::".__METHOD__."::Project->mail_day::".$project->mail_day); if (Carbon::parse($project->mail_day)->dayOfWeek < $endDate->dayOfWeek) { $endDate->next($project->mail_day); } /** * @var ProjectMosaic $mosaic */ $mosaic = $project->mosaics()->updateOrCreate( [ 'name' => sprintf('Week_%s_%s', $endDate->week, $endDate->year), ], [ 'name' => sprintf('Week_%s_%s', $endDate->week, $endDate->year), 'path' => sprintf('%s/%s/%s', $project->download_path, 'mosaics', sprintf('week_%s_%s.tif', $endDate->week, $endDate->year) ), 'end_date' => $endDate->format('Y-m-d'), 'offset' => $offset, ]); return new self($mosaic); } private function throwIfOutputContainsError(string $output) { if (str_contains($output, 'No images available this week, empty mosaic created')) { throw new \RuntimeException( $output); } return true; } }