protected function registerFailedJobsListener()
    {
        if (!in_array($this->app->environment(), config('nodes.bugsnag.notify_release_stages', []))) {
            return;
        }

        $shouldReport = config('nodes.bugsnag.report_failed_jobs');

        if ($shouldReport) {
            Queue::failing(function (JobFailed $event) {
                $exception = $event->exception;
                $meta = [
                    'job' => [
                        'name'     => $event->job->getName(),
                        'queue'    => $event->job->getQueue(),
                        'raw_body' => $event->job->getRawBody(),
                    ],
                    'connection' => [
                        'name' => $event->connectionName,
                    ],
                ];

                app('nodes.bugsnag')->notifyException($exception, function (\Bugsnag\Report $report) use ($meta) {
                    $report->setMetaData($meta, true);
                });
            });
        }
    }