wip process

This commit is contained in:
guillaume91 2024-06-19 15:52:10 +02:00
parent 64fcacb013
commit 85ee4724ee
2 changed files with 42 additions and 13 deletions

View file

@ -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)");

View file

@ -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;