jobData->generateFingerprint(); // Check if job already exists by fingerprint or external_id $existingJob = Job::where('fingerprint', $fingerprint) ->orWhere(function ($query) { $query->where('job_source_id', $this->source->id) ->where('external_id', $this->jobData->externalId); }) ->first(); if ($existingJob) { // Update existing job with fresh data $existingJob->update(array_merge( $this->jobData->toArray(), [ 'job_source_id' => $this->source->id, 'fingerprint' => $fingerprint, ] )); Log::debug("Updated existing job: {$this->jobData->title}"); } else { // Create new job Job::create(array_merge( $this->jobData->toArray(), [ 'job_source_id' => $this->source->id, 'fingerprint' => $fingerprint, ] )); Log::debug("Created new job: {$this->jobData->title}"); } } catch (\Exception $e) { Log::error("Failed to process job listing", [ 'source' => $this->source->name, 'external_id' => $this->jobData->externalId, 'title' => $this->jobData->title, 'error' => $e->getMessage(), ]); throw $e; } } /** * Handle a job failure. */ public function failed(\Throwable $exception): void { Log::error("Failed to process job listing after {tries} attempts", [ 'source' => $this->source->name, 'external_id' => $this->jobData->externalId, 'tries' => $this->tries, 'error' => $exception->getMessage(), ]); } }