ailixir-api / app /Jobs /UpdateAiJobStatus.php
AILIXIR Bot
Auto-sync: 201d269f287526269b8ffded5f450ff36b46c740
907b200
Raw
History Blame Contribute Delete
1 kB
<?php
namespace App\Jobs;
use App\Services\AiService;
use App\Models\AiJob;
use Illuminate\Foundation\Queue\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\SerializesModels;
class UpdateAiJobStatus implements ShouldQueue
{
use InteractsWithQueue, Queueable, SerializesModels;
protected $aiJob;
public function __construct(AiJob $aiJob)
{
$this->aiJob = $aiJob;
}
public function handle(AiService $aiService)
{
$statusResponse = $aiService->status($this->aiJob->job_id);
$previewResponse = $aiService->preview($this->aiJob->job_id);
$this->aiJob->update([
'status' => $statusResponse['status'] ?? $this->aiJob->status,
'preview' => $previewResponse ?? $this->aiJob->preview
]);
if (($statusResponse['status'] ?? '') === 'running') {
self::dispatch($this->aiJob)->delay(now()->addSeconds(30));
}
}
}