You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Laravel任务重复执行问题求助:单次调度任务多次触发

Laravel队列任务重复执行问题求助

我在Laravel应用中遇到了任务重复执行的问题。仅调度了一次任务:

dispatch(new SendFirebaseNotificationJob($data));

但监控队列运行命令:

artisan queue:work  --sleep=3 --tries=0 --backoff=3 --max-time=3600

时,发现同一个任务的handle方法被多次触发(4次、6次甚至10次),日志如下:

2023-05-21 23:31:24 App\Jobs\SendFirebaseNotificationJob ..... 108.77ms DONE
  2023-05-21 23:31:57 App\Jobs\SendFirebaseNotificationJob ........... RUNNING

  2023-05-21 23:31:57 App\Jobs\SendFirebaseNotificationJob ..... 152.49ms DONE
  2023-05-21 23:32:24 App\Jobs\SendFirebaseNotificationJob ...........  2023-05-21 23:32:24 App\Jobs\SendFirebaseNotificationJob ........... RUNNING

 RUNNING

  2023-05-21 23:32:24 App\Jobs\SendFirebaseNotificationJob ..... 209.73ms DONE
  2023-05-21 23:32:24 App\Jobs\SendFirebaseNotificationJob ..... 444.06ms DONE
  2023-05-21 23:37:24 App\Jobs\SendFirebaseNotificationJob  2023-05-21 23:37:24 App\Jobs\SendFirebaseNotificationJob  2023-05-21 23:37:24 App\Jobs\SendFirebaseNotificationJob  2023-05-21 23:37:24 App\Jobs\SendFirebaseNotificationJob  2023-05-21 23:37:24 App\Jobs\SendFirebaseNotificationJob  2023-05-21 23:37:24 App\Jobs\SendFirebaseNotificationJob  2023-05-21 23:37:24 App\Jobs\SendFirebaseNotificationJob  2023-05-21 23:37:24 App\Jobs\SendFirebaseNotificationJob  2023-05-21 23:37:24 App\Jobs\SendFirebaseNotificationJob  2023-05-21 23:37:24 App\Jobs\SendFirebaseNotificationJob ........... RUNNING
 ........... RUNNING
 ........... RUNNING
 ........... RUNNING
 ........... RUNNING
 ........... RUNNING
 ........... RUNNING
 ........... RUNNING
 ........... RUNNING
 ........... RUNNING
Processing job with UID: 764 <- //The same job start mutabile times!
Processing job with UID: 764
Processing job with UID: 764
Processing job with UID: 764
Processing job with UID: 764
Processing job with UID: 764
Processing job with UID: 764
Processing job with UID: 764
Processing job with UID: 764
Processing job with UID: 764
  2023-05-21 23:37:24 App\Jobs\SendFirebaseNotificationJob ..... 131.32ms DONE
  2023-05-21 23:37:24 App\Jobs\SendFirebaseNotificationJob ..... 131.92ms DONE
  2023-05-21 23:37:24 App\Jobs\SendFirebaseNotificationJob .....  2023-05-21 23:37:24 App\Jobs\SendFirebaseNotificationJob ..... 159.31ms DONE
 155.82ms DONE
  2023-05-21 23:37:24 App\Jobs\SendFirebaseNotificationJob ..... 156.36ms DONE
  2023-05-21 23:37:24 App\Jobs\SendFirebaseNotificationJob ..... 156.24ms DONE
  2023-05-21 23:37:24 App\Jobs\SendFirebaseNotificationJob ..... 156.36ms DONE
  2023-05-21 23:37:24 App\Jobs\SendFirebaseNotificationJob ..... 156.58ms DONE
  2023-05-21 23:37:24 App\Jobs\SendFirebaseNotificationJob ..... 192.53ms DONE
  2023-05-21 23:37:24 App\Jobs\SendFirebaseNotificationJob ..... 237.49ms DONE
  2023-05-21 23:41:28 App\Jobs\SendFirebaseNotificationJob ........... RUNNING
  2023-05-21 23:41:28 App\Jobs\SendFirebaseNotificationJob ........... RUNNING

已做排查:

  • 检查过任务的幂等性
  • 删除过数据库中的任务请求,避免重复调度

但问题仍存在,需要让任务仅执行一次,求解决建议或指导。


内容的提问来源于stack exchange,提问作者Bashar Al Masri

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.21 07:02:04