Skip to content

Commit

Permalink
Report job failures to failed jobs provider (#31)
Browse files Browse the repository at this point in the history
* Report job failures to failed jobs provider

* sort imports

Co-authored-by: Till Krüss <[email protected]>
  • Loading branch information
georgeboot and tillkruss authored Nov 21, 2022
1 parent 330cbfd commit c12daec
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion src/BrefServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,11 @@
use Illuminate\Contracts\Http\Kernel;
use Illuminate\Contracts\Events\Dispatcher;

use Illuminate\Queue\Events\JobFailed;
use Illuminate\Queue\Events\JobProcessed;
use Illuminate\Queue\Events\JobProcessing;
use Illuminate\Queue\Events\JobExceptionOccurred;
use Illuminate\Queue\Failed\FailedJobProviderInterface;

class BrefServiceProvider extends ServiceProvider
{
Expand Down Expand Up @@ -67,7 +69,7 @@ public function register()
*
* @return void
*/
public function boot(Dispatcher $dispatcher, LogManager $logManager)
public function boot(Dispatcher $dispatcher, LogManager $logManager, FailedJobProviderInterface $queueFailer)
{
if ($this->app->runningInConsole()) {
$this->publishes([
Expand Down Expand Up @@ -99,6 +101,15 @@ public function boot(Dispatcher $dispatcher, LogManager $logManager)
['name' => $event->job->resolveName()]
)
);

$dispatcher->listen(
fn (JobFailed $event) => $queueFailer->log(
$event->connectionName,
$event->job->getQueue(),
$event->job->getRawBody(),
$event->exception
)
);
}

/**
Expand Down

0 comments on commit c12daec

Please sign in to comment.