77
88namespace Magento \Indexer \Model ;
99
10+ use Magento \Framework \App \ObjectManager ;
11+ use Psr \Log \LoggerInterface ;
12+
1013/**
1114 * Provide functionality for executing user functions in multi-thread mode.
1215 */
@@ -29,15 +32,22 @@ class ProcessManager
2932 /** @var int|null */
3033 private $ threadsCount ;
3134
35+ /**
36+ * @var LoggerInterface
37+ */
38+ private $ logger ;
39+
3240 /**
3341 * @param \Magento\Framework\App\ResourceConnection $resource
3442 * @param \Magento\Framework\Registry $registry
3543 * @param int|null $threadsCount
44+ * @param LoggerInterface|null $logger
3645 */
3746 public function __construct (
3847 \Magento \Framework \App \ResourceConnection $ resource ,
3948 \Magento \Framework \Registry $ registry = null ,
40- int $ threadsCount = null
49+ int $ threadsCount = null ,
50+ LoggerInterface $ logger = null
4151 ) {
4252 $ this ->resource = $ resource ;
4353 if (null === $ registry ) {
@@ -47,6 +57,9 @@ public function __construct(
4757 }
4858 $ this ->registry = $ registry ;
4959 $ this ->threadsCount = (int )$ threadsCount ;
60+ $ this ->logger = $ logger ?? ObjectManager::getInstance ()->get (
61+ LoggerInterface::class
62+ );
5063 }
5164
5265 /**
@@ -135,11 +148,20 @@ private function isSetupMode(): bool
135148 */
136149 private function startChildProcess (callable $ userFunction )
137150 {
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+ }
143165 }
144166
145167 /**
0 commit comments