@@ -40,6 +40,8 @@ class Worker extends \Illuminate\Queue\Worker implements
40
40
41
41
protected $ job ;
42
42
43
+ protected $ extensions = [];
44
+
43
45
public function daemon ($ connectionName , $ queueNames , WorkerOptions $ options )
44
46
{
45
47
$ this ->connectionName = $ connectionName ;
@@ -56,7 +58,9 @@ public function daemon($connectionName, $queueNames, WorkerOptions $options)
56
58
}
57
59
58
60
$ context = $ this ->queue ->getQueueInteropContext ();
59
- $ queueConsumer = new QueueConsumer ($ context , new ChainExtension ([$ this ]));
61
+ $ queueConsumer = new QueueConsumer ($ context , new ChainExtension (
62
+ $ this ->getAllExtensions ([$ this ])
63
+ ));
60
64
foreach (explode (', ' , $ queueNames ) as $ queueName ) {
61
65
$ queueConsumer ->bindCallback ($ queueName , function () {
62
66
$ this ->runJob ($ this ->job , $ this ->connectionName , $ this ->options );
@@ -85,10 +89,10 @@ public function runNextJob($connectionName, $queueNames, WorkerOptions $options)
85
89
86
90
$ context = $ this ->queue ->getQueueInteropContext ();
87
91
88
- $ queueConsumer = new QueueConsumer ($ context , new ChainExtension ([
92
+ $ queueConsumer = new QueueConsumer ($ context , new ChainExtension ($ this -> getAllExtensions ( [
89
93
$ this ,
90
94
new LimitConsumedMessagesExtension (1 ),
91
- ]));
95
+ ]))) ;
92
96
93
97
foreach (explode (', ' , $ queueNames ) as $ queueName ) {
94
98
$ queueConsumer ->bindCallback ($ queueName , function () {
@@ -163,5 +167,20 @@ public function stop($status = 0)
163
167
164
168
parent ::stop ($ status );
165
169
}
166
- }
167
170
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