-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathQueuewatchServiceProvider.php
More file actions
73 lines (61 loc) · 2.04 KB
/
QueuewatchServiceProvider.php
File metadata and controls
73 lines (61 loc) · 2.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
<?php
namespace Queuewatch\Laravel;
use Illuminate\Queue\Events\JobFailed;
use Illuminate\Support\Facades\Event;
use Illuminate\Support\Facades\Route;
use Illuminate\Support\ServiceProvider;
use Queuewatch\Laravel\Api\QueuewatchClient;
use Queuewatch\Laravel\Commands\ListFailedCommand;
use Queuewatch\Laravel\Commands\QueuewatchTestCommand;
use Queuewatch\Laravel\Http\Controllers\RetryController;
use Queuewatch\Laravel\Listeners\ReportFailedJob;
class QueuewatchServiceProvider extends ServiceProvider
{
public function boot(): void
{
if ($this->app->runningInConsole()) {
$this->commands([
ListFailedCommand::class,
QueuewatchTestCommand::class,
]);
$this->publishes([
__DIR__.'/../config/queuewatch.php' => config_path('queuewatch.php'),
], 'queuewatch-config');
}
$this->registerFailedJobListener();
$this->registerRetryRoute();
}
public function register(): void
{
$this->mergeConfigFrom(
__DIR__.'/../config/queuewatch.php',
'queuewatch'
);
$this->app->singleton(QueuewatchClient::class, function ($app) {
return new QueuewatchClient(
config('queuewatch.api_key'),
config('queuewatch.endpoint'),
config('queuewatch.timeout')
);
});
}
protected function registerFailedJobListener(): void
{
if (! config('queuewatch.enabled', true)) {
return;
}
if (empty(config('queuewatch.api_key'))) {
return;
}
Event::listen(JobFailed::class, ReportFailedJob::class);
}
protected function registerRetryRoute(): void
{
if (! config('queuewatch.retry.enabled', false)) {
return;
}
Route::post(config('queuewatch.retry.path', 'queuewatch/retry'), RetryController::class)
->middleware(config('queuewatch.retry.middleware', []))
->name('queuewatch.retry');
}
}