45 lines
1.1 KiB
PHP
45 lines
1.1 KiB
PHP
<?php
|
|
|
|
namespace App\Jobs;
|
|
|
|
use App\Imports\ArtistDataImport;
|
|
use Illuminate\Bus\Queueable;
|
|
use Illuminate\Support\Facades\Storage;
|
|
use Illuminate\Queue\SerializesModels;
|
|
use Illuminate\Queue\InteractsWithQueue;
|
|
use Illuminate\Contracts\Queue\ShouldQueue;
|
|
use Illuminate\Foundation\Bus\Dispatchable;
|
|
use Maatwebsite\Excel\Facades\Excel;
|
|
|
|
//use Illuminate\Foundation\Queue\Queueable;
|
|
|
|
class ImportArtistJob implements ShouldQueue
|
|
{
|
|
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
|
|
|
|
protected string $filePath;
|
|
public $timeout = 3600;
|
|
|
|
/**
|
|
* Create a new job instance.
|
|
*/
|
|
public function __construct(string $filePath)
|
|
{
|
|
$this->filePath = $filePath;
|
|
}
|
|
|
|
/**
|
|
* Execute the job.
|
|
*/
|
|
public function handle(): void
|
|
{
|
|
ini_set('memory_limit', '-1'); // ✅ 增加記憶體限制
|
|
|
|
Excel::import(new ArtistDataImport, $this->filePath);
|
|
// 匯入完成後刪除檔案
|
|
if (Storage::exists($this->filePath)) {
|
|
Storage::delete($this->filePath);
|
|
}
|
|
}
|
|
}
|