Skip to content

Commit 5d98db5

Browse files
BaDosshiftedreality
authored andcommitted
MAGECLOUD-4052: Add variable to change lock providers. (#586)
1 parent f6b14ad commit 5d98db5

File tree

7 files changed

+89
-8
lines changed

7 files changed

+89
-8
lines changed

dist/.magento.env.yaml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -320,6 +320,19 @@
320320
# - consumer1 #
321321
# - consumer2 #
322322
#######################################################################################################################
323+
# LOCK_PROVIDER - use to set the lock provider. #
324+
# The lock provider prevents the launch of duplicate cron jobs and cron groups. #
325+
# You must use the file lock provider in the Production environment. Starter environments and #
326+
# the Pro Integration environment do not use the MAGENTO_CLOUD_LOCKS_DIR variable, so ece-tools #
327+
# applies the db lock provider automatically. #
328+
# Magento Version: 2.2.5 and later #
329+
# Default value: "file" #
330+
# Stages: deploy #
331+
# Example: #
332+
# stage: #
333+
# deploy: #
334+
# LOCK_PROVIDER: "db" #
335+
#######################################################################################################################
323336
# CACHE_CONFIGURATION - use to configure Redis page and default caching. By default, the deployment process #
324337
# overwrites all settings in the env.php file. When setting the cm_cache_backend_redis #
325338
# parameter, you must specify the server, port, and database options. #

src/Config/Schema.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -282,6 +282,17 @@ public function getSchema()
282282
StageConfigInterface::STAGE_GLOBAL => '',
283283
],
284284
],
285+
DeployInterface::VAR_LOCK_PROVIDER => [
286+
self::SCHEMA_TYPE => ['string'],
287+
self::SCHEMA_STAGE => [
288+
StageConfigInterface::STAGE_GLOBAL,
289+
StageConfigInterface::STAGE_DEPLOY
290+
],
291+
self::SCHEMA_VALUE_VALIDATION => ['db', 'file'],
292+
self::SCHEMA_DEFAULT_VALUE => [
293+
StageConfigInterface::STAGE_DEPLOY => 'file',
294+
],
295+
],
285296
DeployInterface::VAR_REDIS_USE_SLAVE_CONNECTION => [
286297
self::SCHEMA_TYPE => ['boolean'],
287298
self::SCHEMA_STAGE => [

src/Config/Stage/DeployInterface.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,11 @@ interface DeployInterface extends StageConfigInterface
2525
const VAR_UPDATE_URLS = 'UPDATE_URLS';
2626
const VAR_FORCE_UPDATE_URLS = 'FORCE_UPDATE_URLS';
2727

28+
/**
29+
* The variable responsible to set lock provider for Magento 2.2.5 and higher.
30+
*/
31+
const VAR_LOCK_PROVIDER = 'LOCK_PROVIDER';
32+
2833
/**
2934
* The variable responsible to set Redis slave connection when it has true value.
3035
*/

src/Process/Deploy/InstallUpdate/ConfigUpdate/Lock/Config.php

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
namespace Magento\MagentoCloud\Process\Deploy\InstallUpdate\ConfigUpdate\Lock;
77

88
use Magento\MagentoCloud\Config\Environment;
9+
use Magento\MagentoCloud\Config\Stage\DeployInterface;
910

1011
/**
1112
* Returns lock configuration.
@@ -17,12 +18,19 @@ class Config
1718
*/
1819
private $environment;
1920

21+
/**
22+
* @var DeployInterface
23+
*/
24+
private $stageConfig;
25+
2026
/**
2127
* @param Environment $environment
28+
* @param DeployInterface $stageConfig
2229
*/
23-
public function __construct(Environment $environment)
30+
public function __construct(Environment $environment, DeployInterface $stageConfig)
2431
{
2532
$this->environment = $environment;
33+
$this->stageConfig = $stageConfig;
2634
}
2735

2836
/**
@@ -36,7 +44,7 @@ public function __construct(Environment $environment)
3644
public function get(): array
3745
{
3846
$lockPath = $this->environment->getEnv('MAGENTO_CLOUD_LOCKS_DIR');
39-
if ($lockPath) {
47+
if ($lockPath && $this->stageConfig->get(DeployInterface::VAR_LOCK_PROVIDER) === 'file') {
4048
return [
4149
'provider' => 'file',
4250
'config' => [

src/Test/Functional/Acceptance/AcceptanceCest.php

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -150,18 +150,21 @@ protected function defaultDataProvider(): array
150150
],
151151
],
152152
],
153-
'test cron_consumers_runner with wrong array' => [
153+
'test cron_consumers_runner with wrong array, there is MAGENTO_CLOUD_LOCKS_DIR, LOCK_PROVIDER is db' => [
154154
'cloudVariables' => [
155155
'MAGENTO_CLOUD_VARIABLES' => [
156156
'ADMIN_EMAIL' => 'admin@example.com',
157+
'LOCK_PROVIDER' => 'db',
157158
'CRON_CONSUMERS_RUNNER' => [
158159
'cron_run' => 'true',
159160
'max_messages' => 5000,
160161
'consumers' => ['test'],
161162
],
162163
],
163164
],
164-
'rawVariables' => [],
165+
'rawVariables' => [
166+
'MAGENTO_CLOUD_LOCKS_DIR' => '/tmp/locks',
167+
],
165168
'expectedConfig' => [
166169
'cron_consumers_runner' => [
167170
'cron_run' => false,
@@ -171,6 +174,12 @@ protected function defaultDataProvider(): array
171174
'directories' => [
172175
'document_root_is_pub' => true,
173176
],
177+
'lock' => [
178+
'provider' => 'db',
179+
'config' => [
180+
'prefix' => null,
181+
],
182+
],
174183
],
175184
],
176185
'test cron_consumers_runner with string' => [

src/Test/Unit/Config/SchemaTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ public function testGetDefaultsForDeploy()
7878
DeployInterface::VAR_ENABLE_GOOGLE_ANALYTICS => false,
7979
DeployInterface::VAR_SCD_MATRIX => [],
8080
DeployInterface::VAR_RESOURCE_CONFIGURATION => [],
81+
DeployInterface::VAR_LOCK_PROVIDER => 'file',
8182
],
8283
$this->schema->getDefaults(StageConfigInterface::STAGE_DEPLOY)
8384
);

src/Test/Unit/Process/Deploy/InstallUpdate/ConfigUpdate/lock/ConfigTest.php

Lines changed: 38 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
use Magento\MagentoCloud\Process\Deploy\InstallUpdate\ConfigUpdate\Lock\Config;
99
use Magento\MagentoCloud\Config\Environment;
10+
use Magento\MagentoCloud\Config\Stage\DeployInterface;
1011
use PHPUnit\Framework\TestCase;
1112
use PHPUnit_Framework_MockObject_MockObject as Mock;
1213

@@ -20,6 +21,11 @@ class ConfigTest extends TestCase
2021
*/
2122
private $environmentMock;
2223

24+
/**
25+
* @var DeployInterface|Mock
26+
*/
27+
private $stageConfigMock;
28+
2329
/**
2430
* @var Config
2531
*/
@@ -31,20 +37,26 @@ class ConfigTest extends TestCase
3137
protected function setUp()
3238
{
3339
$this->environmentMock = $this->createMock(Environment::class);
34-
$this->config = new Config($this->environmentMock);
40+
$this->stageConfigMock = $this->getMockForAbstractClass(DeployInterface::class);
41+
$this->config = new Config($this->environmentMock, $this->stageConfigMock);
3542
}
3643

3744
/**
3845
* @param $lockPath
46+
* @param string $lockProvider
3947
* @param array $expectedResult
4048
* @dataProvider getDataProvider
4149
*/
42-
public function testGet($lockPath, array $expectedResult)
50+
public function testGet($lockPath, $lockProvider, array $expectedResult)
4351
{
4452
$this->environmentMock->expects($this->once())
4553
->method('getEnv')
4654
->with('MAGENTO_CLOUD_LOCKS_DIR')
4755
->willReturn($lockPath);
56+
$this->stageConfigMock->expects($this->any())
57+
->method('get')
58+
->with(DeployInterface::VAR_LOCK_PROVIDER)
59+
->willReturn($lockProvider);
4860
$this->assertSame($expectedResult, $this->config->get());
4961
}
5062

@@ -54,17 +66,39 @@ public function testGet($lockPath, array $expectedResult)
5466
public function getDataProvider(): array
5567
{
5668
return [
57-
'There is MAGENTO_CLOUD_LOCKS_DIR' => [
69+
'There is MAGENTO_CLOUD_LOCKS_DIR and LOCK_PROVIDER is file' => [
5870
'lockPath' => '/tmp/locks',
71+
'lockProvider' => 'file',
5972
'expectedResult' => [
6073
'provider' => 'file',
6174
'config' => [
6275
'path' => '/tmp/locks',
6376
],
6477
],
6578
],
66-
'There is no MAGENTO_CLOUD_LOCKS_DIR' => [
79+
'There is MAGENTO_CLOUD_LOCKS_DIR and LOCK_PROVIDER is db' => [
80+
'lockPath' => '/tmp/locks',
81+
'lockProvider' => 'db',
82+
'expectedResult' => [
83+
'provider' => 'db',
84+
'config' => [
85+
'prefix' => null,
86+
],
87+
],
88+
],
89+
'There is no MAGENTO_CLOUD_LOCKS_DIR and LOCK_PROVIDER is file' => [
90+
'lockPath' => null,
91+
'lockProvider' => 'file',
92+
'expectedResult' => [
93+
'provider' => 'db',
94+
'config' => [
95+
'prefix' => null,
96+
],
97+
],
98+
],
99+
'There is no MAGENTO_CLOUD_LOCKS_DIR and LOCK_PROVIDER is db' => [
67100
'lockPath' => null,
101+
'lockProvider' => 'db',
68102
'expectedResult' => [
69103
'provider' => 'db',
70104
'config' => [

0 commit comments

Comments
 (0)