filePath = $filePath; } /** * Execute the job. */ public function handle(): void { //ini_set('memory_limit', '-1'); // 無限記憶體,適合大量匯入 try { Excel::import(new SongDataImport, $this->filePath); // 匯入成功後再刪檔案 if (Storage::exists($this->filePath)) { Storage::delete($this->filePath); } } catch (\Throwable $e) { // 寫入錯誤日誌 \Log::error('ImportSongJob failed: ' . $e->getMessage(), [ 'trace' => $e->getTraceAsString(), 'file' => $this->filePath ]); // ❗重要:不要刪除檔案,讓失敗時可以 retry 使用同一份檔案 throw $e; // 讓 Laravel Queue 系統可以 retry } } }