php - 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 中跟踪作业?
谢谢!
解决方案
推荐阅读
- node.js - 代码管道将 S3 存储桶作为用户参数传递给 AWS 中的 lambda 函数
- php - PHP - 为类数组创建方法
- ibm-watson - Watson 助手 API 获取令牌返回 403 ERCD NOCONFIG 错误
- python - 检测 LED 阵列中的缺陷 LED
- python - 创建了一个 PyPi 包,但安装后无法导入模块
- sapui5 - 使用 Web IDE 创建简单的货物移动屏幕
- javascript - clearInterval() 没有停止间隔
- photoeditorsdk - 为什么我在导出时无法从 photoeditorsdk 获取数据 url?
- python - pyrad 获取明文密码
- java - Android 在 MainActivity 中调用自定义适配器方法