首页 > 解决方案 > Laravel 批处理队列导致 MySQL 错误

问题描述

我有一些任务,人们可以通过在仪表板中切换来运行。我创建了一个任务模型,它跟踪所有作业也被调度的批次 ID。

我首先在批处理上运行主作业,例如:

$batchQueue = [];
foreach ($formulas as $brand => $formula) {
   $batchQueue[] = new UpdateFormulaJob($client, $brand, $formula);
}

然后在 UpdateFormulaJob 中,我将循环遍历产品,然后在我添加到链中的另一个作业中更新每个产品品牌,例如:

$batchQueue = [];
$products->each(function ($product) use ($price_formula, &$batchQueue) {
   $batchQueue[] = new UpdateProductPrice($price_formula, $product->product_id);
});
$this->batch()->add($batchQueue);

尽管我不断收到错误出现在哨兵中,并且批次永远不会出现以下错误:

SQLSTATE[HY000]: General error: 1205 Lock wait timeout exceeded; try restarting transaction (SQL: update `job_batches` set `total_jobs` = total_jobs + 4579, `pending_jobs` = pending_jobs + 4579, `finished_at` = ? where `id` = 941787bf-b05c-4d49-81cc-2a9e66e90ac2)
SQLSTATE[HY000]: General error: 1205 Lock wait timeout exceeded; try restarting transaction (SQL: select * from `job_batches` where `id` = 941787bf-b05c-4d49-81cc-2a9e66e90ac2 limit 1 for update)

我已尝试将所有内容移至控制器,然后仅将 UpdateProductPrice 分派到队列,但似乎 MySQL 无法跟上 SQS 队列?

有谁知道我可以在没有作业批次的情况下做到这一点,并可能在 redis 中跟踪作业?

谢谢!

标签: phpmysqllaravelamazon-sqslaravel-queue

解决方案


推荐阅读