diff --git a/app/Jobs/ImportSongJob.php b/app/Jobs/ImportSongJob.php index d6bb70a..e988316 100644 --- a/app/Jobs/ImportSongJob.php +++ b/app/Jobs/ImportSongJob.php @@ -18,7 +18,7 @@ class ImportSongJob implements ShouldQueue use Dispatchable, InteractsWithQueue, Queueable, SerializesModels; protected string $filePath; - public $timeout = 36000; + //public $timeout = 36000; /** * Create a new job instance. @@ -33,12 +33,25 @@ class ImportSongJob implements ShouldQueue */ public function handle(): void { - ini_set('memory_limit', '-1'); // ✅ 增加記憶體限制 + //ini_set('memory_limit', '-1'); // 無限記憶體,適合大量匯入 - Excel::import(new SongDataImport, $this->filePath); - // 匯入完成後刪除檔案 - if (Storage::exists($this->filePath)) { - Storage::delete($this->filePath); + 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 } } } diff --git a/開發手冊.ini b/開發手冊.ini index 24a17cc..af6e0d7 100644 --- a/開發手冊.ini +++ b/開發手冊.ini @@ -96,7 +96,7 @@ php artisan make:observer RoomObserver --model=Room - +php artisan queue:work composer install