improve queue error handling

This commit is contained in:
Daniël Klabbers 2019-10-18 13:13:30 +02:00
parent 62e1a8e5c2
commit 2febb2653f
2 changed files with 23 additions and 0 deletions

View File

@ -67,6 +67,7 @@ class Server
$error = $registry->handle($event->getError());
/** @var Reporter[] $reporters */
$reporters = $app->tagged(Reporter::class);
if ($error->shouldBeReported()) {

View File

@ -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());
}
}
});
}
}