linkedid = $linkedid; } // ========================================================================= public function handle(): void { $linkedid = $this->linkedid; $lockKey = "call-direct-lock:{$linkedid}"; // SET NX ensures at most one worker processes each linkedid at a time. if (! Redis::set($lockKey, 1, 'EX', self::LOCK_TTL, 'NX')) { if (CompanySettings::get(SettingsHelper::S_COMPANY_CONSOLE_DEBUG_LOGS)) { Log::info("[ProcessDirectCallJob] Lock already held for {$linkedid} — skipping duplicate."); } return; } try { if (InboundReport::where('linkedid', $linkedid)->exists()) { if (CompanySettings::get(SettingsHelper::S_COMPANY_CONSOLE_DEBUG_LOGS)) { Log::info("[ProcessDirectCallJob] Report already exists for {$linkedid} — skipping."); } return; } app(DirectCallsService::class)->processSingleDirectCall($linkedid); } catch (\Throwable $e) { Redis::del($lockKey); if (CompanySettings::get(SettingsHelper::S_COMPANY_CONSOLE_DEBUG_LOGS)) { Log::error("[ProcessDirectCallJob] Failed for {$linkedid}: " . $e->getMessage()); } throw $e; } } public function failed(\Throwable $exception): void { if (CompanySettings::get(SettingsHelper::S_COMPANY_CONSOLE_DEBUG_LOGS)) { Log::error("[ProcessDirectCallJob] All attempts exhausted for {$this->linkedid}: " . $exception->getMessage()); } } // ========================================================================= }