繁体   English   中英

如何判断 Laravel 当前是否正在运行排队作业?

[英]How to tell if Laravel is currently running a queued job?

我需要调整我的 Laravel 应用程序的全局异常处理程序以记录ModelNotFoundException错误,但仅当从排队作业中抛出异常时。 我想使用全局异常处理程序(而不是直接修改我的作业),因此更改适用于排队的作业、消息、闭包等。

在我的\App\Exceptions\Handler class 中:

    /**
     * Determine if the exception is in the "do not report" list.
     *
     * @param  \Throwable  $e
     * @return bool
     */
    protected function shouldntReport(Throwable $e)
    {
        $runningInQueue = // ... logic to detect whether this is running in a background queue
        if ($e instanceof ModelNotFoundException && $runningInQueue) {
            return false;
        }
        return parent::shouldReport($e)
    }

如果我要覆盖上面的逻辑,那么获取$runningInQueue变量的 true/false 值的最佳方法是什么?

也许app()->runningInConsole()

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM