@@ -36,7 +36,7 @@ protected static function getCommand(array $options): string
3636 global $ argv ;
3737 $ command = empty ($ options ['command ' ]) ? implode (' ' , $ argv ) : $ options ['command ' ];
3838
39- return trim ((string ) $ command );
39+ return trim ((string )$ command );
4040 }
4141
4242 public static function getChildProcessErrorHandling (): string
@@ -126,7 +126,7 @@ public static function initProcessManager(?int $monitoringId, array $options = [
126126 $ monitoringItem ->setName ($ config ->getName ())->save ();
127127 }
128128 if (!$ config ->getActive ()) {
129- exit ('ProcessManager: Config with ID ' . $ config ->getId (). ' is disabled - exiting ' );
129+ exit ('ProcessManager: Config with ID ' . $ config ->getId () . ' is disabled - exiting ' );
130130 }
131131 }
132132 $ values = $ config instanceof \Elements \Bundle \ProcessManagerBundle \Model \Configuration ? $ config ->getExecutorClassObject ()->getValues () : $ options ;
@@ -189,9 +189,9 @@ protected static function doUniqueExecutionCheck(mixed $config, array $options):
189189 ElementsProcessManagerBundle::getMonitoringItem ()->delete ();
190190 }
191191 }
192- ElementsProcessManagerBundle::getMonitoringItem ()->getLogger ()->info ('Another process with the PID ' . getmypid (). ' started. Exiting Process: ' . getmypid ());
192+ ElementsProcessManagerBundle::getMonitoringItem ()->getLogger ()->info ('Another process with the PID ' . getmypid () . ' started. Exiting Process: ' . getmypid ());
193193 ElementsProcessManagerBundle::setMonitoringItem (null );
194- exit ("\n\nProcessManager: $ count " . ($ count > 1 ? 'processes running ' : 'process running ' ). " - exiting \n\n" );
194+ exit ("\n\nProcessManager: $ count " . ($ count > 1 ? 'processes running ' : 'process running ' ) . " - exiting \n\n" );
195195 }
196196 }
197197
@@ -230,7 +230,7 @@ public function setCommandObject(mixed $commandObject)
230230 */
231231 public static function checkExecutingUser (array $ allowedUsers = []): void
232232 {
233- $ configFile = PIMCORE_WEB_ROOT . '/index.php ' ;
233+ $ configFile = PIMCORE_WEB_ROOT . '/index.php ' ;
234234 $ owner = fileowner ($ configFile );
235235
236236 if ($ owner === false ) {
@@ -245,7 +245,7 @@ public static function checkExecutingUser(array $allowedUsers = []): void
245245 $ scriptExecutingUser = $ scriptExecutingUserData ['name ' ];
246246
247247 if (!in_array ($ scriptExecutingUser , $ allowedUsers )) {
248- throw new \Exception ("The current system user is not allowed to execute this script. Allowed users: ' " . implode (', ' , $ allowedUsers ) ."' Executing user: ' $ scriptExecutingUser'. " );
248+ throw new \Exception ("The current system user is not allowed to execute this script. Allowed users: ' " . implode (', ' , $ allowedUsers ) . "' Executing user: ' $ scriptExecutingUser'. " );
249249 }
250250 }
251251 }
@@ -270,7 +270,8 @@ public static function executeChildProcesses(MonitoringItem $monitoringItem, arr
270270 foreach ($ childProcesses as $ c ) {
271271 $ c ->delete ();
272272 }
273- $ monitoringItem ->setCurrentWorkload (0 )->setTotalWorkload (count ($ workload ))->setMessage ('Starting child processes ' )->save ();
273+ $ totalWorkload = count ($ workloadChunks );
274+ $ monitoringItem ->setCurrentWorkload (0 )->setTotalWorkload ($ totalWorkload )->setMessage ('Starting child processes ' )->save ();
274275
275276 $ i = 0 ;
276277 foreach ($ workloadChunks as $ i => $ package ) {
@@ -281,12 +282,12 @@ public static function executeChildProcesses(MonitoringItem $monitoringItem, arr
281282 continue ;
282283 }
283284
284- $ monitoringItem ->setMessage ('Processing batch ' . ($ i + 1 ) . ' of ' . count ( $ workloadChunks ) )->save ();
285+ $ monitoringItem ->setMessage ('Processing batch ' . ($ i + 1 ) . ' of ' . $ totalWorkload )->save ();
285286
286287 for ($ x = 1 ; $ x <= 3 ; $ x ++) {
287288 $ result = Helper::executeJob ($ monitoringItem ->getConfigurationId (), $ monitoringItem ->getCallbackSettings (), 0 , $ package , $ monitoringItem ->getId (), $ callback );
288289
289- if ($ result ['success ' ] == false ) {
290+ if (! $ result ['success ' ]) {
290291 $ attempts = $ i === 1 ? "$ i time " : "$ i times " ;
291292 $ monitoringItem ->getLogger ()->warning ("Can't start child (tried $ attempts) - reason: " . $ result ['message ' ]);
292293
@@ -298,9 +299,9 @@ public static function executeChildProcesses(MonitoringItem $monitoringItem, arr
298299 break ;
299300 }
300301 }
301- self ::waitForChildProcesses ($ monitoringItem , $ i * $ batchSize , $ numberOfchildProcesses );
302+ self ::waitForChildProcesses ($ monitoringItem , $ i , $ numberOfchildProcesses );
302303 }
303- self ::waitForChildProcesses ($ monitoringItem , $ i * $ batchSize );
304+ self ::waitForChildProcesses ($ monitoringItem , $ i, $ numberOfchildProcesses );
304305 }
305306
306307 /**
@@ -322,12 +323,12 @@ protected static function childProcessCheck(MonitoringItem $monitoringItem): voi
322323
323324 if ($ mItem ) {
324325 $ mItem ->stopProcess ();
325- $ mItem ->setMessage ('Killed by MonitoringItem ID ' . $ monitoringItem ->getId (). ' because child process failed ' , false )->save ();
326+ $ mItem ->setMessage ('Killed by MonitoringItem ID ' . $ monitoringItem ->getId () . ' because child process failed ' , false )->save ();
326327 }
327328 }
328329 }
329330
330- throw new \Exception ('Exiting because child failed: ' .print_r ($ statuses ['details ' ][MonitoringItem::STATUS_FAILED ], true ));
331+ throw new \Exception ('Exiting because child failed: ' . print_r ($ statuses ['details ' ][MonitoringItem::STATUS_FAILED ], true ));
331332 }
332333
333334 }
@@ -348,13 +349,13 @@ protected static function childProcessCheck(MonitoringItem $monitoringItem): voi
348349 *
349350 * @throws \Exception
350351 */
351- protected static function waitForChildProcesses (MonitoringItem $ monitoringItem , int $ baseline , int $ maxProcesses = 0 ): void
352+ protected static function waitForChildProcesses (MonitoringItem $ monitoringItem , int $ currentBatchIteration , int $ maxProcesses = 0 ): void
352353 {
353354 do {
354355 $ status = $ monitoringItem ->getChildProcessesStatus ();
355356 $ activeProcesses = $ status ['summary ' ]['active ' ];
356357
357- $ monitoringItem ->setCurrentWorkload ($ baseline + $ status ['currentWorkload ' ] )->save ();
358+ $ monitoringItem ->setCurrentWorkload (( int )( $ status [ ' summary ' ][ ' finished ' ] + $ status ['summary ' ][ ' failed ' ]) )->save ();
358359
359360 $ monitoringItem ->getLogger ()->info ('Waiting to start child processes -> status: ' . print_r ($ status ['summary ' ], true ));
360361 static ::childProcessCheck ($ monitoringItem );
0 commit comments