[done] ProjectDownloadJob for the rds: triggers this job right after a download is successful.
This commit is contained in:
parent
355dbfe984
commit
e9db62bcbf
68
laravel_app/app/Jobs/ProjectDownloadRDSJob.php
Normal file
68
laravel_app/app/Jobs/ProjectDownloadRDSJob.php
Normal 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);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -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([]);
|
||||
|
|
|
|||
Loading…
Reference in a new issue