From 2febb2653fbc94466dc6ac3d99a3c5c815acb0e6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dani=C3=ABl=20Klabbers?= Date: Fri, 18 Oct 2019 13:13:30 +0200 Subject: [PATCH] improve queue error handling --- framework/core/src/Console/Server.php | 1 + .../core/src/Queue/QueueServiceProvider.php | 22 +++++++++++++++++++ 2 files changed, 23 insertions(+) diff --git a/framework/core/src/Console/Server.php b/framework/core/src/Console/Server.php index fd0b5a1f4..8fc591724 100644 --- a/framework/core/src/Console/Server.php +++ b/framework/core/src/Console/Server.php @@ -67,6 +67,7 @@ class Server $error = $registry->handle($event->getError()); + /** @var Reporter[] $reporters */ $reporters = $app->tagged(Reporter::class); if ($error->shouldBeReported()) { diff --git a/framework/core/src/Queue/QueueServiceProvider.php b/framework/core/src/Queue/QueueServiceProvider.php index 56c0b12e2..fec8182bf 100644 --- a/framework/core/src/Queue/QueueServiceProvider.php +++ b/framework/core/src/Queue/QueueServiceProvider.php @@ -13,11 +13,14 @@ namespace Flarum\Queue; use Flarum\Console\Event\Configuring; use Flarum\Foundation\AbstractServiceProvider; +use Flarum\Foundation\ErrorHandling\Registry; +use Flarum\Foundation\ErrorHandling\Reporter; use Illuminate\Contracts\Debug\ExceptionHandler as ExceptionHandling; use Illuminate\Contracts\Queue\Factory; use Illuminate\Contracts\Queue\Queue; use Illuminate\Queue\Connectors\ConnectorInterface; use Illuminate\Queue\Console as Commands; +use Illuminate\Queue\Events\JobFailed; use Illuminate\Queue\Failed\NullFailedJobProvider; use Illuminate\Queue\Listener as QueueListener; use Illuminate\Queue\SyncQueue; @@ -109,4 +112,23 @@ class QueueServiceProvider extends AbstractServiceProvider } }); } + + public function boot() + { + $this->app['events']->listen(JobFailed::class, function (JobFailed $event) { + /** @var Registry $registry */ + $registry = $this->app->make(Registry::class); + + $error = $registry->handle($event->exception); + + /** @var Reporter[] $reporters */ + $reporters = $this->app->tagged(Reporter::class); + + if ($error->shouldBeReported()) { + foreach ($reporters as $reporter) { + $reporter->report($error->getException()); + } + } + }); + } }