$this->filePath, 'user_id' => $this->userId, ]); $import = null; if ($this->importId) { $import = Import::find($this->importId); } try { $service = new ImportSparePartsService($this->filePath, $this->userId); $result = $service->handle(); if ($import) { if ($result['success']) { $import->update([ 'status' => Import::STATUS_COMPLETED, 'result' => implode("\n", $result['logs']), ]); } else { $import->update([ 'status' => Import::STATUS_FAILED, 'result' => implode("\n", $result['logs']) . "\n\nОШИБКА: " . ($result['error'] ?? 'Неизвестная ошибка'), ]); } } Log::info("ImportSparePartsJob finished successfully"); } catch (\Exception $e) { Log::error("ImportSparePartsJob failed: " . $e->getMessage(), [ 'trace' => $e->getTraceAsString(), ]); if ($import) { $import->update([ 'status' => Import::STATUS_FAILED, 'result' => "ОШИБКА: " . $e->getMessage() . "\n\n" . $e->getTraceAsString(), ]); } throw $e; } finally { // Удаляем временный файл if (file_exists($this->filePath)) { unlink($this->filePath); } } } }