9
9
*/
10
10
namespace Magento \Cron \Observer ;
11
11
12
+ use Laminas \Http \PhpEnvironment \Request as Environment ;
12
13
use Exception ;
13
14
use Magento \Cron \Model \DeadlockRetrierInterface ;
14
15
use Magento \Cron \Model \ResourceModel \Schedule \Collection as ScheduleCollection ;
@@ -133,6 +134,16 @@ class ProcessCronQueueObserver implements ObserverInterface
133
134
*/
134
135
protected $ dateTime ;
135
136
137
+ /**
138
+ * @var Environment
139
+ */
140
+ private Environment $ environment ;
141
+
142
+ /**
143
+ * @var string
144
+ */
145
+ private string $ originalProcessTitle ;
146
+
136
147
/**
137
148
* @var \Symfony\Component\Process\PhpExecutableFinder
138
149
*/
@@ -189,6 +200,7 @@ class ProcessCronQueueObserver implements ObserverInterface
189
200
* @param \Magento\Framework\Lock\LockManagerInterface $lockManager
190
201
* @param \Magento\Framework\Event\ManagerInterface $eventManager
191
202
* @param DeadlockRetrierInterface $retrier
203
+ * @param Environment $environment
192
204
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
193
205
*/
194
206
public function __construct (
@@ -206,7 +218,8 @@ public function __construct(
206
218
StatFactory $ statFactory ,
207
219
\Magento \Framework \Lock \LockManagerInterface $ lockManager ,
208
220
\Magento \Framework \Event \ManagerInterface $ eventManager ,
209
- DeadlockRetrierInterface $ retrier
221
+ DeadlockRetrierInterface $ retrier ,
222
+ Environment $ environment
210
223
) {
211
224
$ this ->_objectManager = $ objectManager ;
212
225
$ this ->_scheduleFactory = $ scheduleFactory ;
@@ -216,6 +229,7 @@ public function __construct(
216
229
$ this ->_request = $ request ;
217
230
$ this ->_shell = $ shell ;
218
231
$ this ->dateTime = $ dateTime ;
232
+ $ this ->environment = $ environment ;
219
233
$ this ->phpExecutableFinder = $ phpExecutableFinderFactory ->create ();
220
234
$ this ->logger = $ logger ;
221
235
$ this ->state = $ state ;
@@ -354,6 +368,8 @@ protected function _runJob($scheduledTime, $currentTime, $jobConfig, $schedule,
354
368
);
355
369
}
356
370
371
+ $ this ->setProcessTitle ($ jobCode , $ groupId );
372
+
357
373
$ schedule ->setExecutedAt (date ('Y-m-d H:i:s ' , $ this ->dateTime ->gmtTimestamp ()));
358
374
$ this ->retrier ->execute (
359
375
function () use ($ schedule ) {
@@ -944,4 +960,24 @@ function () use ($scheduleResource, $where) {
944
960
$ scheduleResource ->getConnection ()
945
961
);
946
962
}
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
+ }
947
983
}
0 commit comments