File tree Expand file tree Collapse file tree 2 files changed +50
-0
lines changed Expand file tree Collapse file tree 2 files changed +50
-0
lines changed Original file line number Diff line number Diff line change
1
+ <?php
2
+
3
+ namespace VladimirYuldashev \LaravelQueueRabbitMQ \Horizon \Listeners ;
4
+
5
+ use Illuminate \Contracts \Events \Dispatcher ;
6
+ use Laravel \Horizon \Events \JobFailed as HorizonJobFailed ;
7
+ use Illuminate \Queue \Events \JobFailed as LaravelJobFailed ;
8
+ use VladimirYuldashev \LaravelQueueRabbitMQ \Queue \Jobs \RabbitMQJob ;
9
+
10
+ class RabbitMQFailedEvent
11
+ {
12
+ /**
13
+ * The event dispatcher implementation.
14
+ *
15
+ * @var \Illuminate\Contracts\Events\Dispatcher
16
+ */
17
+ public $ events ;
18
+
19
+ /**
20
+ * Create a new listener instance.
21
+ *
22
+ * @param \Illuminate\Contracts\Events\Dispatcher $events
23
+ * @return void
24
+ */
25
+ public function __construct (Dispatcher $ events )
26
+ {
27
+ $ this ->events = $ events ;
28
+ }
29
+
30
+ /**
31
+ * Handle the event.
32
+ *
33
+ * @param \Illuminate\Queue\Events\JobFailed $event
34
+ * @return void
35
+ */
36
+ public function handle (LaravelJobFailed $ event )
37
+ {
38
+ if (! $ event ->job instanceof RabbitMQJob) {
39
+ return ;
40
+ }
41
+
42
+ $ this ->events ->dispatch ((new HorizonJobFailed (
43
+ $ event ->exception , $ event ->job , $ event ->job ->getRawBody ()
44
+ ))->connection ($ event ->connectionName )->queue ($ event ->job ->getQueue ()));
45
+ }
46
+ }
Original file line number Diff line number Diff line change 6
6
use Interop \Amqp \AmqpContext ;
7
7
use InvalidArgumentException ;
8
8
use Illuminate \Contracts \Queue \Queue ;
9
+ use Illuminate \Queue \Events \JobFailed ;
9
10
use Interop \Amqp \AmqpConnectionFactory ;
10
11
use Enqueue \AmqpTools \DelayStrategyAware ;
11
12
use Illuminate \Contracts \Events \Dispatcher ;
15
16
use VladimirYuldashev \LaravelQueueRabbitMQ \Queue \RabbitMQQueue ;
16
17
use Interop \Amqp \AmqpConnectionFactory as InteropAmqpConnectionFactory ;
17
18
use Enqueue \AmqpLib \AmqpConnectionFactory as EnqueueAmqpConnectionFactory ;
19
+ use VladimirYuldashev \LaravelQueueRabbitMQ \Horizon \Listeners \RabbitMQFailedEvent ;
18
20
use VladimirYuldashev \LaravelQueueRabbitMQ \Horizon \RabbitMQQueue as HorizonRabbitMQQueue ;
19
21
20
22
class RabbitMQConnector implements ConnectorInterface
@@ -79,6 +81,8 @@ public function connect(array $config): Queue
79
81
}
80
82
81
83
if ($ worker === 'horizon ' ) {
84
+ $ this ->dispatcher ->listen (JobFailed::class, RabbitMQFailedEvent::class);
85
+
82
86
return new HorizonRabbitMQQueue ($ context , $ config );
83
87
}
84
88
You can’t perform that action at this time.
0 commit comments