Skip to content

Commit 20cc5ac

Browse files
author
Bohdan Korablov
committed
MAGETWO-93161: Fix Problems with Consumer Runners on Cloud Clusters
1 parent 37d2ab2 commit 20cc5ac

File tree

3 files changed

+28
-10
lines changed

3 files changed

+28
-10
lines changed

app/code/Magento/MessageQueue/Model/Cron/ConsumersRunner.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,8 @@ private function canBeRun($consumerName, array $allowedConsumers = [])
139139
*/
140140
private function getPidFilePath($consumerName)
141141
{
142-
return $consumerName . static::PID_FILE_EXT;
142+
$sanitizedHostname = preg_replace('/[^a-zA-Z0-9]/i', '', gethostname());
143+
144+
return $consumerName . '-' . $sanitizedHostname . static::PID_FILE_EXT;
143145
}
144146
}

app/code/Magento/MessageQueue/Test/Unit/Model/Cron/ConsumersRunnerTest.php

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,8 @@ class ConsumersRunnerTest extends \PHPUnit\Framework\TestCase
5151
*/
5252
protected function setUp()
5353
{
54+
require_once __DIR__ . '/../../_files/consumers_runner_functions_mocks.php';
55+
5456
$this->phpExecutableFinderMock = $this->getMockBuilder(phpExecutableFinder::class)
5557
->disableOriginalConstructor()
5658
->getMock();
@@ -116,7 +118,7 @@ public function testRun(
116118
$isRunExpects
117119
) {
118120
$consumerName = 'consumerName';
119-
$pidFilePath = 'consumerName.pid';
121+
$pidFilePath = 'consumerName-myHostName.pid';
120122

121123
$this->deploymentConfigMock->expects($this->exactly(3))
122124
->method('get')
@@ -164,7 +166,7 @@ public function runDataProvider()
164166
'isRun' => false,
165167
'php' => '',
166168
'command' => 'php '. BP . '/bin/magento queue:consumers:start %s %s %s',
167-
'arguments' => ['consumerName', '--pid-file-path=consumerName.pid', '--max-messages=20000'],
169+
'arguments' => ['consumerName', '--pid-file-path=consumerName-myHostName.pid', '--max-messages=20000'],
168170
'allowedConsumers' => [],
169171
'shellBackgroundExpects' => 1,
170172
'isRunExpects' => 1,
@@ -174,7 +176,7 @@ public function runDataProvider()
174176
'isRun' => false,
175177
'php' => '',
176178
'command' => 'php '. BP . '/bin/magento queue:consumers:start %s %s %s',
177-
'arguments' => ['consumerName', '--pid-file-path=consumerName.pid', '--max-messages=10000'],
179+
'arguments' => ['consumerName', '--pid-file-path=consumerName-myHostName.pid', '--max-messages=10000'],
178180
'allowedConsumers' => [],
179181
'shellBackgroundExpects' => 1,
180182
'isRunExpects' => 1,
@@ -184,7 +186,7 @@ public function runDataProvider()
184186
'isRun' => false,
185187
'php' => '',
186188
'command' => 'php '. BP . '/bin/magento queue:consumers:start %s %s %s',
187-
'arguments' => ['consumerName', '--pid-file-path=consumerName.pid', '--max-messages=10000'],
189+
'arguments' => ['consumerName', '--pid-file-path=consumerName-myHostName.pid', '--max-messages=10000'],
188190
'allowedConsumers' => ['someConsumer'],
189191
'shellBackgroundExpects' => 0,
190192
'isRunExpects' => 0,
@@ -194,7 +196,7 @@ public function runDataProvider()
194196
'isRun' => true,
195197
'php' => '',
196198
'command' => 'php '. BP . '/bin/magento queue:consumers:start %s %s %s',
197-
'arguments' => ['consumerName', '--pid-file-path=consumerName.pid', '--max-messages=10000'],
199+
'arguments' => ['consumerName', '--pid-file-path=consumerName-myHostName.pid', '--max-messages=10000'],
198200
'allowedConsumers' => ['someConsumer'],
199201
'shellBackgroundExpects' => 0,
200202
'isRunExpects' => 0,
@@ -204,7 +206,7 @@ public function runDataProvider()
204206
'isRun' => true,
205207
'php' => '',
206208
'command' => 'php '. BP . '/bin/magento queue:consumers:start %s %s %s',
207-
'arguments' => ['consumerName', '--pid-file-path=consumerName.pid', '--max-messages=10000'],
209+
'arguments' => ['consumerName', '--pid-file-path=consumerName-myHostName.pid', '--max-messages=10000'],
208210
'allowedConsumers' => [],
209211
'shellBackgroundExpects' => 0,
210212
'isRunExpects' => 1,
@@ -214,7 +216,7 @@ public function runDataProvider()
214216
'isRun' => true,
215217
'php' => '',
216218
'command' => 'php '. BP . '/bin/magento queue:consumers:start %s %s %s',
217-
'arguments' => ['consumerName', '--pid-file-path=consumerName.pid', '--max-messages=10000'],
219+
'arguments' => ['consumerName', '--pid-file-path=consumerName-myHostName.pid', '--max-messages=10000'],
218220
'allowedConsumers' => ['consumerName'],
219221
'shellBackgroundExpects' => 0,
220222
'isRunExpects' => 1,
@@ -224,7 +226,7 @@ public function runDataProvider()
224226
'isRun' => false,
225227
'php' => '',
226228
'command' => 'php '. BP . '/bin/magento queue:consumers:start %s %s %s',
227-
'arguments' => ['consumerName', '--pid-file-path=consumerName.pid', '--max-messages=10000'],
229+
'arguments' => ['consumerName', '--pid-file-path=consumerName-myHostName.pid', '--max-messages=10000'],
228230
'allowedConsumers' => ['consumerName'],
229231
'shellBackgroundExpects' => 1,
230232
'isRunExpects' => 1,
@@ -234,7 +236,7 @@ public function runDataProvider()
234236
'isRun' => false,
235237
'php' => '/bin/php',
236238
'command' => '/bin/php '. BP . '/bin/magento queue:consumers:start %s %s',
237-
'arguments' => ['consumerName', '--pid-file-path=consumerName.pid'],
239+
'arguments' => ['consumerName', '--pid-file-path=consumerName-myHostName.pid'],
238240
'allowedConsumers' => ['consumerName'],
239241
'shellBackgroundExpects' => 1,
240242
'isRunExpects' => 1,
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Magento\MessageQueue\Model\Cron;
7+
8+
/**
9+
* @return string
10+
*/
11+
function gethostname()
12+
{
13+
return 'myHost@Name';
14+
}

0 commit comments

Comments
 (0)