W3Cschool
恭喜您成為首批注冊用戶
獲得88經(jīng)驗值獎勵
要分發(fā)任務(wù),你應(yīng)該使用 Bus
facade 的 batch
方法。當(dāng)然,你可以和批處理的回調(diào)結(jié)合使用。因此,你可以使用 then
,catch
和 finally
方法來定義批處理的回調(diào),這些回調(diào)中每一個在調(diào)用時都會接收到一個 Illuminate\Bus\Batch
實例:
use App\Jobs\ProcessPodcast;
use App\Podcast;
use Illuminate\Bus\Batch;
use Illuminate\Support\Facades\Batch;
use Throwable;
$batch = Bus::batch([
new ProcessPodcast(Podcast::find(1)),
new ProcessPodcast(Podcast::find(2)),
new ProcessPodcast(Podcast::find(3)),
new ProcessPodcast(Podcast::find(4)),
new ProcessPodcast(Podcast::find(5)),
])->then(function (Batch $batch) {
// 所有任務(wù)已成功完成...
})->catch(function (Batch $batch, Throwable $e) {
// 檢測到第一個失敗的任務(wù)...
})->finally(function (Batch $batch) {
// 批處理執(zhí)行完畢...
})->dispatch();
return $batch->id;
Copyright©2021 w3cschool編程獅|閩ICP備15016281號-3|閩公網(wǎng)安備35020302033924號
違法和不良信息舉報電話:173-0602-2364|舉報郵箱:jubao@eeedong.com
掃描二維碼
下載編程獅App
編程獅公眾號
聯(lián)系方式:
更多建議: