SmartCane/laravel_app/app/Jobs/ProjectInterpolateGrowthModelJob.php
2024-07-09 15:47:53 +02:00

52 lines
1.3 KiB
PHP

<?php
namespace App\Jobs;
use App\Models\Project;
use Carbon\Carbon;
use Illuminate\Bus\Batchable;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\SerializesModels;
use Illuminate\Support\Facades\Log;
use Symfony\Component\Process\Process;
class ProjectInterpolateGrowthModelJob implements ShouldQueue
{
use Batchable, Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
protected Project $project;
protected Carbon $date;
protected int $offset;
public function __construct(Project $project)
{
logger(__CLASS__ . __METHOD__);
$this->project = $project;
}
/**
* Execute the job.
*/
public function handle(): void
{
logger('start interpolate growth model', [$this->project->name]);
$command = [
sprintf('%s/interpolate_growth_model.sh', base_path('../')),
sprintf('--project_dir=%s', $this->project->download_path),
];
$process = new Process($command);
$process->setTimeout(600);
$process->run();
if (!$process->isSuccessful()) {
logger('error', [$process->getErrorOutput()]);
return;
}
logger($process->getOutput());
}
}