1

我有三个 Laravel Parent 工作名称

        AutoPOChargeCalculation::dispatch($invoice_id, $user_id, $notify)->onQueue('invoice');
        AutoSOChargeCalculation::dispatch($invoice_id, $user_id, $notify)->onQueue('invoice');
        AutoSPChargeCalculation::dispatch($invoice_id, $user_id, $notify)->onQueue('invoice');

他们每个人都用 for 循环调用子作业


 foreach ($objects as  $object) {

            $jobs[] = new CalculateSingleSaleOrderCharge($model, $object, $user_id, $notify, $i, $total_objects);
         $i ++;
        }
        Bus::chain($jobs)->onQueue('invoice')->dispatch();
    }
 foreach ($objects as  $object) {

            $jobs[] = new CalculateSinglePurchaseOrderCharge($model, $object, $user_id, $notify, $i, $total_objects);
         $i ++;
        }
        Bus::chain($jobs)->onQueue('invoice')->dispatch();
    }

 foreach ($objects as  $object) {

            $jobs[] = new CalculateSingleStoragePeriodCharge($model, $object, $user_id, $notify, $i, $total_objects);
         $i ++;
        }
        Bus::chain($jobs)->onQueue('invoice')->dispatch();
    }

现在我正在考虑删除父工作并链接所有子工作总线


 Bus::chain($jobs)->onQueue('invoice')->dispatch()->withChain(
 Bus::chain($jobs)->onQueue('invoice')->dispatch())->withChain(
 Bus::chain($jobs)->onQueue('invoice')->dispatch());


Is that Possible?

4

1 回答 1

1

随着新的 Laravel 8 更新,您现在可以将一批作业发送到队列,除此之外,您还可以批量链接作业。

use App\Jobs\ReleasePodcast;
use App\Jobs\SendPodcastReleaseNotification;
use Illuminate\Bus\Batch;
use Illuminate\Support\Facades\Bus;

Bus::batch([
    [
        new ReleasePodcast(1),
        new SendPodcastReleaseNotification(1),
    ],
    [
        new ReleasePodcast(2),
        new SendPodcastReleaseNotification(2),
    ],
])->then(function (Batch $batch) {
    // ...
})->dispatch();

在这里查看文档。批次内的链 - Laravel 8

于 2021-02-18T15:31:52.167 回答