@@ -15,30 +15,47 @@ class ProcessManager
15
15
*/
16
16
const THREADS_COUNT = 'MAGE_INDEXER_THREADS_COUNT ' ;
17
17
18
+ /**
19
+ * Configuration path for threads count
20
+ */
21
+ const THREADS_COUNT_CONFIG_PATH = 'indexer/threads_count ' ;
22
+
18
23
/** @var bool */
19
24
private $ failInChildProcess = false ;
20
25
21
26
/** @var \Magento\Framework\App\ResourceConnection */
22
27
private $ resource ;
23
28
29
+ /** @var \Magento\Framework\App\DeploymentConfig */
30
+ private $ deploymentConfig ;
31
+
32
+ /** @var \Magento\Framework\Registry */
33
+ private $ registry ;
34
+
24
35
/** @var int|null */
25
- private $ threadsCount ;
36
+ private $ threadsCountFromEnvVariable ;
26
37
27
38
/**
28
39
* @param \Magento\Framework\App\ResourceConnection $resource
40
+ * @param \Magento\Framework\App\DeploymentConfig $deploymentConfig
41
+ * @param \Magento\Framework\Registry $registry
29
42
* @param int|null $threadsCount
30
43
*/
31
44
public function __construct (
32
- \Magento \Framework \App \ResourceConnection $ resource = null ,
45
+ \Magento \Framework \App \ResourceConnection $ resource ,
46
+ \Magento \Framework \App \DeploymentConfig $ deploymentConfig ,
47
+ \Magento \Framework \Registry $ registry = null ,
33
48
int $ threadsCount = null
34
49
) {
35
- if (null === $ resource ) {
36
- $ resource = \Magento \Framework \App \ObjectManager::getInstance ()->get (
37
- \Magento \Framework \App \ResourceConnection::class
50
+ $ this ->resource = $ resource ;
51
+ $ this ->deploymentConfig = $ deploymentConfig ;
52
+ if (null === $ registry ) {
53
+ $ registry = \Magento \Framework \App \ObjectManager::getInstance ()->get (
54
+ \Magento \Framework \Registry::class
38
55
);
39
56
}
40
- $ this ->resource = $ resource ;
41
- $ this ->threadsCount = ( int ) $ threadsCount ;
57
+ $ this ->registry = $ registry ;
58
+ $ this ->threadsCountFromEnvVariable = $ threadsCount ;
42
59
}
43
60
44
61
/**
@@ -48,7 +65,7 @@ public function __construct(
48
65
*/
49
66
public function execute ($ userFunctions )
50
67
{
51
- if ($ this ->threadsCount > 1 && $ this ->isCanBeParalleled ()) {
68
+ if ($ this ->getThreadsCount () > 1 && $ this ->isCanBeParalleled () && ! $ this -> isSetupMode () && PHP_SAPI == ' cli ' ) {
52
69
$ this ->multiThreadsExecute ($ userFunctions );
53
70
} else {
54
71
$ this ->simpleThreadExecute ($ userFunctions );
@@ -106,6 +123,32 @@ private function isCanBeParalleled()
106
123
return function_exists ('pcntl_fork ' );
107
124
}
108
125
126
+ /**
127
+ * Get threads count
128
+ *
129
+ * @return bool
130
+ */
131
+ private function getThreadsCount ()
132
+ {
133
+ if ($ this ->threadsCountFromEnvVariable !== null ) {
134
+ return (int )$ this ->threadsCountFromEnvVariable ;
135
+ }
136
+ if ($ this ->deploymentConfig ->get (self ::THREADS_COUNT_CONFIG_PATH ) !== null ) {
137
+ return (int )$ this ->deploymentConfig ->get (self ::THREADS_COUNT_CONFIG_PATH );
138
+ }
139
+ return 1 ;
140
+ }
141
+
142
+ /**
143
+ * Is setup mode
144
+ *
145
+ * @return bool
146
+ */
147
+ private function isSetupMode ()
148
+ {
149
+ return $ this ->registry ->registry ('setup-mode-enabled ' ) ?: false ;
150
+ }
151
+
109
152
/**
110
153
* Start child process
111
154
*
@@ -127,7 +170,7 @@ private function startChildProcess($userFunction)
127
170
private function executeParentProcess (&$ threadNumber )
128
171
{
129
172
$ threadNumber ++;
130
- if ($ threadNumber >= $ this ->threadsCount ) {
173
+ if ($ threadNumber >= $ this ->getThreadsCount () ) {
131
174
pcntl_wait ($ status );
132
175
if (pcntl_wexitstatus ($ status ) !== 0 ) {
133
176
$ this ->failInChildProcess = true ;
0 commit comments