7
7
8
8
namespace Magento \Indexer \Model ;
9
9
10
+ use Magento \Framework \App \ObjectManager ;
11
+ use Psr \Log \LoggerInterface ;
12
+
10
13
/**
11
14
* Provide functionality for executing user functions in multi-thread mode.
12
15
*/
@@ -29,15 +32,22 @@ class ProcessManager
29
32
/** @var int|null */
30
33
private $ threadsCount ;
31
34
35
+ /**
36
+ * @var LoggerInterface
37
+ */
38
+ private $ logger ;
39
+
32
40
/**
33
41
* @param \Magento\Framework\App\ResourceConnection $resource
34
42
* @param \Magento\Framework\Registry $registry
35
43
* @param int|null $threadsCount
44
+ * @param LoggerInterface|null $logger
36
45
*/
37
46
public function __construct (
38
47
\Magento \Framework \App \ResourceConnection $ resource ,
39
48
\Magento \Framework \Registry $ registry = null ,
40
- int $ threadsCount = null
49
+ int $ threadsCount = null ,
50
+ LoggerInterface $ logger = null
41
51
) {
42
52
$ this ->resource = $ resource ;
43
53
if (null === $ registry ) {
@@ -47,6 +57,9 @@ public function __construct(
47
57
}
48
58
$ this ->registry = $ registry ;
49
59
$ this ->threadsCount = (int )$ threadsCount ;
60
+ $ this ->logger = $ logger ?? ObjectManager::getInstance ()->get (
61
+ LoggerInterface::class
62
+ );
50
63
}
51
64
52
65
/**
@@ -135,11 +148,20 @@ private function isSetupMode(): bool
135
148
*/
136
149
private function startChildProcess (callable $ userFunction )
137
150
{
138
- // phpcs:ignore Magento2.Functions.DiscouragedFunction
139
- $ status = call_user_func ($ userFunction );
140
- $ status = is_int ($ status ) ? $ status : 0 ;
141
- // phpcs:ignore Magento2.Security.LanguageConstruct.ExitUsage
142
- exit ($ status );
151
+ try {
152
+ // phpcs:ignore Magento2.Functions.DiscouragedFunction
153
+ $ status = call_user_func ($ userFunction );
154
+ $ status = is_int ($ status ) ? $ status : 0 ;
155
+ } catch (\Throwable $ e ) {
156
+ $ status = 1 ;
157
+ $ this ->logger ->error (
158
+ __ ('Child process failed with message: %1 ' , $ e ->getMessage ()),
159
+ ['exception ' => $ e ]
160
+ );
161
+ } finally {
162
+ // phpcs:ignore Magento2.Security.LanguageConstruct.ExitUsage
163
+ exit ($ status );
164
+ }
143
165
}
144
166
145
167
/**
0 commit comments