[done] ProjectDownloadJob for the rds: triggers this job right after a download is successful.

This commit is contained in:
guillaume91 2024-06-26 11:46:51 +02:00
parent 355dbfe984
commit e9db62bcbf
3 changed files with 73 additions and 2 deletions

View file

@ -0,0 +1,68 @@
<?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 ProjectDownloadRDSJob implements ShouldQueue
{
use Batchable, Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
protected Project $project;
protected Carbon $date;
protected int $offset;
public function __construct(Project $project,Carbon $date,int $offset)
{
$this->project = $project;
$this->date = $date;
$this->offset = $offset;
}
/**
* Execute the job.
*/
public function handle(): void
{
$command = [
sprintf('%sbuild_RDS.sh', base_path('../')),
sprintf('--end_date=%s', $this->date->format('Y-m-d')),
sprintf('--offset=%d', $this->offset),
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());
}
/**
* Handle the job for a date range
*/
public static function fromDate(Project $project,Carbon $date,int $offset = 1):NullJob|ProjectDownloadRDSJob
{
$filename = $date->format('Y-m-d') . '.tif';
if ($project->downloads()->statusSuccess()->where(['name' => $filename])->exists()) {
Log::warning("The download $filename can be processed. Please check it's status.");
return new NullJob();
}
return new self($project,$date,$offset);
}
}

View file

@ -11,6 +11,8 @@
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\SerializesModels;
use Carbon\Carbon;
use Illuminate\Support\Facades\Bus;
use Symfony\Component\Process\Process;
class ProjectDownloadTiffJob implements ShouldQueue
@ -52,9 +54,10 @@ public function handle(): void
$this->download->setStatusFailed();
return;
}
// Success
logger($process->getOutput());
$this->download->setStatusSuccess();
Bus::dispatch(ProjectDownloadRDSJob::fromDate($this->download->project,$this->days));
}
public static function handleForDate(Project $project, Carbon $date)

View file

@ -361,7 +361,7 @@ public function hasMissingDownloadsDateInHarvestFile():bool
return $this->getMissingDownloadsDateInHarvestFile()->count() > 0;
}
public function getMissingDownloadsDateInHarvestFile()
public function getMissingDownloadsDateInHarvestFile():Collection
{
if(!$this->harvest_json_path || !$this->min_harvest_date){
return collect([]);