@@ -40,6 +40,8 @@ class Worker extends \Illuminate\Queue\Worker implements
4040
4141 protected $ job ;
4242
43+ protected $ extensions = [];
44+
4345 public function daemon ($ connectionName , $ queueNames , WorkerOptions $ options )
4446 {
4547 $ this ->connectionName = $ connectionName ;
@@ -56,7 +58,9 @@ public function daemon($connectionName, $queueNames, WorkerOptions $options)
5658 }
5759
5860 $ context = $ this ->queue ->getQueueInteropContext ();
59- $ queueConsumer = new QueueConsumer ($ context , new ChainExtension ([$ this ]));
61+ $ queueConsumer = new QueueConsumer ($ context , new ChainExtension (
62+ $ this ->getAllExtensions ([$ this ])
63+ ));
6064 foreach (explode (', ' , $ queueNames ) as $ queueName ) {
6165 $ queueConsumer ->bindCallback ($ queueName , function () {
6266 $ this ->runJob ($ this ->job , $ this ->connectionName , $ this ->options );
@@ -85,10 +89,10 @@ public function runNextJob($connectionName, $queueNames, WorkerOptions $options)
8589
8690 $ context = $ this ->queue ->getQueueInteropContext ();
8791
88- $ queueConsumer = new QueueConsumer ($ context , new ChainExtension ([
92+ $ queueConsumer = new QueueConsumer ($ context , new ChainExtension ($ this -> getAllExtensions ( [
8993 $ this ,
9094 new LimitConsumedMessagesExtension (1 ),
91- ]));
95+ ]))) ;
9296
9397 foreach (explode (', ' , $ queueNames ) as $ queueName ) {
9498 $ queueConsumer ->bindCallback ($ queueName , function () {
@@ -163,5 +167,20 @@ public function stop($status = 0)
163167
164168 parent ::stop ($ status );
165169 }
166- }
167170
171+ public function setExtensions (array $ extensions ): self
172+ {
173+ $ this ->extensions = $ extensions ;
174+
175+ return $ this ;
176+ }
177+
178+ protected function getAllExtensions (array $ array ): array
179+ {
180+ foreach ($ this ->extensions as $ extension ) {
181+ $ array [] = $ extension ;
182+ }
183+
184+ return $ array ;
185+ }
186+ }
0 commit comments