W3Cschool
恭喜您成為首批注冊(cè)用戶(hù)
獲得88經(jīng)驗(yàn)值獎(jiǎng)勵(lì)
要構(gòu)建可批處理的任務(wù),你應(yīng)該先 創(chuàng)建任務(wù),
然后將 Illuminate\Bus\Batchable
trait 添加到任務(wù)類(lèi),該 trait 提供了對(duì) batch
方法的訪問(wèn),該方法可用于檢索任務(wù)當(dāng)前執(zhí)行的批處理:
<?php
namespace App\Jobs;
use App\Models\Podcast;
use App\Services\AudioProcessor;
use Illuminate\Bus\Batchable;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\SerializesModels;
class ProcessPodcast implements ShouldQueue
{
use Batchable, Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
/**
* 執(zhí)行任務(wù)
*
* @return void
*/
public function handle()
{
if ($this->batch()->cancelled()) {
// 檢測(cè)到批處理取消...
return;
}
// 批處理任務(wù)執(zhí)行...
}
}
Copyright©2021 w3cschool編程獅|閩ICP備15016281號(hào)-3|閩公網(wǎng)安備35020302033924號(hào)
違法和不良信息舉報(bào)電話(huà):173-0602-2364|舉報(bào)郵箱:jubao@eeedong.com
掃描二維碼
下載編程獅App
編程獅公眾號(hào)
聯(lián)系方式:
更多建議: