Al-HUWAITI Shell
Al-huwaiti


Server : LiteSpeed
System : Linux server335.web-hosting.com 4.18.0-553.62.1.lve.el8.x86_64 #1 SMP Mon Jul 21 17:50:35 UTC 2025 x86_64
User : cardxfeb ( 2452)
PHP Version : 8.1.34
Disable Function : NONE
Directory :  /home/cardxfeb/public_html/app/Jobs/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Current File : /home/cardxfeb/public_html/app/Jobs/GenerateAiCardJob.php
<?php

namespace App\Jobs;

use App\Models\Vcard;
use App\Models\User;
use App\Services\AiCardGeneratorService;
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;

class GenerateAiCardJob implements ShouldQueue
{
    use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;

    public int $tries   = 3;
    public int $timeout = 180; // 3 min  multi-source takes longer
    public int $backoff = 30;

    public function __construct(
        public User         $user,
        public string|array $sources,  // single URL or array of URLs
        public int          $vcardId
    ) {}

    public function handle(AiCardGeneratorService $aiService): void
    {
        $vcard = Vcard::findOrFail($this->vcardId);
        $vcard->update(['ai_status' => 'processing']);

        $sourcesCount = is_array($this->sources) ? count($this->sources) : 1;
        Log::info("[GenerateAiCardJob] Starting: user#{$this->user->id}, vcard#{$this->vcardId}, {$sourcesCount} source(s)");

        $result = $aiService->generate($this->user, $this->sources, $vcard);

        if ($result['success']) {
            Log::info("[GenerateAiCardJob] Done: template_id={$result['template_id']}, confidence={$result['confidence']}");
        } else {
            Log::error("[GenerateAiCardJob] Failed: " . ($result['error'] ?? 'unknown'));
            $this->fail(new \Exception($result['error'] ?? 'AI generation failed'));
        }
    }

    public function failed(\Throwable $exception): void
    {
        Vcard::find($this->vcardId)?->update(['ai_status' => 'failed']);
        Log::error("[GenerateAiCardJob] Permanently failed: " . $exception->getMessage());
    }
}

Al-HUWAITI Shell