Skip to content

Commit 0ac321b

Browse files
committed
Preserve (most of the) original command line title
1 parent a2f9e4b commit 0ac321b

File tree

1 file changed

+25
-2
lines changed

1 file changed

+25
-2
lines changed

app/code/Magento/Cron/Observer/ProcessCronQueueObserver.php

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
*/
1010
namespace Magento\Cron\Observer;
1111

12+
use Laminas\Http\PhpEnvironment\Request;
1213
use Magento\Cron\Model\ResourceModel\Schedule\Collection as ScheduleCollection;
1314
use Magento\Cron\Model\Schedule;
1415
use Magento\Framework\App\State;
@@ -128,6 +129,16 @@ class ProcessCronQueueObserver implements ObserverInterface
128129
*/
129130
protected $dateTime;
130131

132+
/**
133+
* @var Request
134+
*/
135+
protected Request $environment;
136+
137+
/**
138+
* @var string
139+
*/
140+
protected string $originalProcessTitle;
141+
131142
/**
132143
* @var \Symfony\Component\Process\PhpExecutableFinder
133144
*/
@@ -201,7 +212,8 @@ public function __construct(
201212
StatFactory $statFactory,
202213
\Magento\Framework\Lock\LockManagerInterface $lockManager,
203214
\Magento\Framework\Event\ManagerInterface $eventManager,
204-
DeadlockRetrierInterface $retrier
215+
DeadlockRetrierInterface $retrier,
216+
Request $environment
205217
) {
206218
$this->_objectManager = $objectManager;
207219
$this->_scheduleFactory = $scheduleFactory;
@@ -211,6 +223,7 @@ public function __construct(
211223
$this->_request = $request;
212224
$this->_shell = $shell;
213225
$this->dateTime = $dateTime;
226+
$this->environment = $environment;
214227
$this->phpExecutableFinder = $phpExecutableFinderFactory->create();
215228
$this->logger = $logger;
216229
$this->state = $state;
@@ -339,7 +352,17 @@ protected function _runJob($scheduledTime, $currentTime, $jobConfig, $schedule,
339352
);
340353
}
341354

342-
cli_set_process_title("Magento cron - group=$groupId - job=$jobCode");
355+
if (!isset($this->originalProcessTitle)) {
356+
$this->originalProcessTitle = implode(' ', $this->environment->getServer('argv'));
357+
}
358+
359+
if (strpos($this->originalProcessTitle, " --group=$groupId ") !== false) {
360+
// Group is already shown, so no need to include here in duplicate
361+
cli_set_process_title($this->originalProcessTitle . " # job: $jobCode");
362+
} else {
363+
cli_set_process_title($this->originalProcessTitle . " # group: $groupId, job: $jobCode");
364+
}
365+
343366
$schedule->setExecutedAt(strftime('%Y-%m-%d %H:%M:%S', $this->dateTime->gmtTimestamp()));
344367
$this->retrier->execute(
345368
function () use ($schedule) {

0 commit comments

Comments
 (0)