99 */
1010namespace Magento \Cron \Observer ;
1111
12+ use Laminas \Http \PhpEnvironment \Request as Environment ;
1213use Exception ;
1314use Magento \Cron \Model \DeadlockRetrierInterface ;
1415use Magento \Cron \Model \ResourceModel \Schedule \Collection as ScheduleCollection ;
@@ -133,6 +134,16 @@ class ProcessCronQueueObserver implements ObserverInterface
133134 */
134135 protected $ dateTime ;
135136
137+ /**
138+ * @var Environment
139+ */
140+ private Environment $ environment ;
141+
142+ /**
143+ * @var string
144+ */
145+ private string $ originalProcessTitle ;
146+
136147 /**
137148 * @var \Symfony\Component\Process\PhpExecutableFinder
138149 */
@@ -189,6 +200,7 @@ class ProcessCronQueueObserver implements ObserverInterface
189200 * @param \Magento\Framework\Lock\LockManagerInterface $lockManager
190201 * @param \Magento\Framework\Event\ManagerInterface $eventManager
191202 * @param DeadlockRetrierInterface $retrier
203+ * @param Environment $environment
192204 * @SuppressWarnings(PHPMD.ExcessiveParameterList)
193205 */
194206 public function __construct (
@@ -206,7 +218,8 @@ public function __construct(
206218 StatFactory $ statFactory ,
207219 \Magento \Framework \Lock \LockManagerInterface $ lockManager ,
208220 \Magento \Framework \Event \ManagerInterface $ eventManager ,
209- DeadlockRetrierInterface $ retrier
221+ DeadlockRetrierInterface $ retrier ,
222+ Environment $ environment
210223 ) {
211224 $ this ->_objectManager = $ objectManager ;
212225 $ this ->_scheduleFactory = $ scheduleFactory ;
@@ -216,6 +229,7 @@ public function __construct(
216229 $ this ->_request = $ request ;
217230 $ this ->_shell = $ shell ;
218231 $ this ->dateTime = $ dateTime ;
232+ $ this ->environment = $ environment ;
219233 $ this ->phpExecutableFinder = $ phpExecutableFinderFactory ->create ();
220234 $ this ->logger = $ logger ;
221235 $ this ->state = $ state ;
@@ -354,6 +368,8 @@ protected function _runJob($scheduledTime, $currentTime, $jobConfig, $schedule,
354368 );
355369 }
356370
371+ $ this ->setProcessTitle ($ jobCode , $ groupId );
372+
357373 $ schedule ->setExecutedAt (date ('Y-m-d H:i:s ' , $ this ->dateTime ->gmtTimestamp ()));
358374 $ this ->retrier ->execute (
359375 function () use ($ schedule ) {
@@ -944,4 +960,24 @@ function () use ($scheduleResource, $where) {
944960 $ scheduleResource ->getConnection ()
945961 );
946962 }
963+
964+ /**
965+ * Set the process title to include the job code and group
966+ *
967+ * @param string $jobCode
968+ * @param string $groupId
969+ */
970+ private function setProcessTitle (string $ jobCode , string $ groupId ): void
971+ {
972+ if (!isset ($ this ->originalProcessTitle )) {
973+ $ this ->originalProcessTitle = PHP_BINARY . ' ' . implode (' ' , $ this ->environment ->getServer ('argv ' ));
974+ }
975+
976+ if (strpos ($ this ->originalProcessTitle , " --group= $ groupId " ) !== false ) {
977+ // Group is already shown, so no need to include here in duplicate
978+ cli_set_process_title ($ this ->originalProcessTitle . " # job: $ jobCode " );
979+ } else {
980+ cli_set_process_title ($ this ->originalProcessTitle . " # group: $ groupId, job: $ jobCode " );
981+ }
982+ }
947983}
0 commit comments