namespace App\Jobs; use App\Models\ApiProvider; use App\Services\Api\ApiServiceManager; 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 SyncProviderServices implements ShouldQueue { use Dispatchable, InteractsWithQueue, Queueable, SerializesModels; public $timeout = 600; public $tries = 2; protected $providerId; public function __construct(int $providerId) { $this->providerId = $providerId; } public function handle(ApiServiceManager $apiManager) { $provider = ApiProvider::find($this->providerId); if (!$provider) { Log::error("Provider {$this->providerId} not found for sync"); return; } Log::info("Starting service sync for provider: {$provider->name}"); try { $result = $apiManager->syncProviderServices($provider); Log::info("Service sync completed for {$provider->name}", $result); } catch (\Exception $e) { Log::error("Service sync failed for {$provider->name}: " . $e->getMessage()); // Mark provider with sync error $provider->update(['status' => 'sync_error']); throw $e; } } }