【发布时间】:2021-09-23 03:46:51
【问题描述】:
我想给潜在的大量客户发送电子邮件,因此我使用批处理并将每封电子邮件作为批处理作业推送,如下所示:
public function __construct(RunReport $runReport, User $run_by) {
$this->runReport = $runReport;
$this->run_by = $run_by;
}
public function handle()
{
$company_detail = CompanyDetail::first();
$jobs = $this->runReport->runReportReportees
->map(fn(RunReportReportee $runReportReportee) => new EmailStatementJob($runReportReportee, $company_detail))
->toArray();
$batch = Bus
::batch($jobs)
->then(function(Batch $batch) {
// All completed
$completed = ($batch->totalJobs - $batch->failedJobs);
$message = "foo";
$type = "bar";
$this->run_by->notify(new GenericNotification($message, $type, 'envelope'));
})
->allowFailures()
->name('Batch name here trust me')
->dispatch();
return $batch->id;
}
但是通知行会导致错误Serialization of 'Doctrine\DBAL\Driver\PDOConnection' is not allowed。
如何在批处理完成后通知发起该批处理的用户以及包含的电子邮件发送尝试的结果?或者,我应该如何向几百个客户发送电子邮件并将结果通知用户?
【问题讨论】:
-
搜索您的错误消息会在 SO 上找到许多解释和建议,您是否经历过所有这些?他们建议您在
GenericNotification中有无法序列化的内容:stackoverflow.com/questions/43643626/…、stackoverflow.com/questions/47475892/…、stackoverflow.com/questions/66420024/… ... -
是的,但我无法理解正在序列化的内容。全部排序。
标签: laravel laravel-queue