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 66use  Interop \Amqp \AmqpContext ;
77use  InvalidArgumentException ;
88use  Illuminate \Contracts \Queue \Queue ;
9+ use  Illuminate \Queue \Events \JobFailed ;
910use  Interop \Amqp \AmqpConnectionFactory ;
1011use  Enqueue \AmqpTools \DelayStrategyAware ;
1112use  Illuminate \Contracts \Events \Dispatcher ;
1516use  VladimirYuldashev \LaravelQueueRabbitMQ \Queue \RabbitMQQueue ;
1617use  Interop \Amqp \AmqpConnectionFactory  as  InteropAmqpConnectionFactory ;
1718use  Enqueue \AmqpLib \AmqpConnectionFactory  as  EnqueueAmqpConnectionFactory ;
19+ use  VladimirYuldashev \LaravelQueueRabbitMQ \Horizon \Listeners \RabbitMQFailedEvent ;
1820use  VladimirYuldashev \LaravelQueueRabbitMQ \Horizon \RabbitMQQueue  as  HorizonRabbitMQQueue ;
1921
2022class  RabbitMQConnector implements  ConnectorInterface
@@ -79,6 +81,8 @@ public function connect(array $config): Queue
7981        }
8082
8183        if  ($ worker  === 'horizon ' ) {
84+             $ this  ->dispatcher ->listen (JobFailed::class, RabbitMQFailedEvent::class);
85+ 
8286            return  new  HorizonRabbitMQQueue ($ context , $ config );
8387        }
8488
    
 
   
 
     
   
   
          
     
  
    
     
 
    
      
     
 
     
    You can’t perform that action at this time.
  
 
    
  
     
    
      
        
     
 
       
      
     
   
 
    
    
  
 
  
 
     
    
0 commit comments