查問題 歌曲線上滙不進去 20250508

This commit is contained in:
allen.yan 2025-05-08 13:27:16 +08:00
parent e53e2402bf
commit 14f7e22d3c
2 changed files with 20 additions and 7 deletions

View File

@ -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
}
}
}

View File

@ -96,7 +96,7 @@ php artisan make:observer RoomObserver --model=Room
php artisan queue:work
composer install