@@ -111,6 +111,7 @@ public function __construct(
111
111
public function run ()
112
112
{
113
113
$ runByCron = $ this ->deploymentConfig ->get ('cron_consumers_runner/cron_run ' , true );
114
+ $ multipleProcesses = $ this ->deploymentConfig ->get ('cron_consumers_runner/multiple_processes ' , []);
114
115
115
116
if (!$ runByCron ) {
116
117
return ;
@@ -125,19 +126,47 @@ public function run()
125
126
continue ;
126
127
}
127
128
128
- $ arguments = [
129
- $ consumer ->getName (),
130
- '--single-thread '
131
- ];
132
-
133
- if ($ maxMessages ) {
134
- $ arguments [] = '--max-messages= ' . min ($ consumer ->getMaxMessages () ?? $ maxMessages , $ maxMessages );
129
+ if (array_key_exists ($ consumer ->getName (), $ multipleProcesses )) {
130
+ $ numberOfProcesses = $ multipleProcesses [$ consumer ->getName ()];
131
+
132
+ for ($ i = 1 ; $ i <= $ numberOfProcesses ; $ i ++) {
133
+ if ($ this ->lockManager ->isLocked (md5 ($ consumer ->getName ()))) { //phpcs:ignore
134
+ continue ;
135
+ }
136
+ $ arguments = [
137
+ $ consumer ->getName (),
138
+ '--multi-process= ' . $ i
139
+ ];
140
+
141
+ if ($ maxMessages ) {
142
+ $ arguments [] = '--max-messages= ' . min ($ consumer ->getMaxMessages () ?? $ maxMessages , $ maxMessages );
143
+ }
144
+
145
+ $ command = $ php . ' ' . BP . '/bin/magento queue:consumers:start %s %s '
146
+ . ($ maxMessages ? ' %s ' : '' );
147
+
148
+ $ this ->shellBackground ->execute ($ command , $ arguments );
149
+ }
150
+ $ this ->lockManager ->lock (md5 ($ consumer ->getName ()));
151
+ } else {
152
+ if ($ this ->lockManager ->isLocked (md5 ($ consumer ->getName ()))) { //phpcs:ignore
153
+ return false ;
154
+ }
155
+
156
+ $ arguments = [
157
+ $ consumer ->getName (),
158
+ '--single-thread '
159
+ ];
160
+
161
+ if ($ maxMessages ) {
162
+ $ arguments [] = '--max-messages= ' . min ($ consumer ->getMaxMessages () ?? $ maxMessages , $ maxMessages );
163
+ }
164
+
165
+ $ command = $ php . ' ' . BP . '/bin/magento queue:consumers:start %s %s '
166
+ . ($ maxMessages ? ' %s ' : '' );
167
+
168
+ $ this ->shellBackground ->execute ($ command , $ arguments );
135
169
}
136
-
137
- $ command = $ php . ' ' . BP . '/bin/magento queue:consumers:start %s %s '
138
- . ($ maxMessages ? ' %s ' : '' );
139
-
140
- $ this ->shellBackground ->execute ($ command , $ arguments );
141
170
}
142
171
}
143
172
@@ -157,10 +186,6 @@ private function canBeRun(ConsumerConfigItemInterface $consumerConfig, array $al
157
186
return false ;
158
187
}
159
188
160
- if ($ this ->lockManager ->isLocked (md5 ($ consumerName ))) { //phpcs:ignore
161
- return false ;
162
- }
163
-
164
189
$ connectionName = $ consumerConfig ->getConnection ();
165
190
try {
166
191
$ this ->mqConnectionTypeResolver ->getConnectionType ($ connectionName );
0 commit comments