Skip to content

Commit

Permalink
Sort procecces in processes command by worker id
Browse files Browse the repository at this point in the history
  • Loading branch information
luzrain committed Sep 29, 2024
1 parent 3b05850 commit 60333d2
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/Internal/SystemPlugin/Command/ProcessesCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ public function execute(Options $options): int
\assert($status instanceof ServerStatus);

if ($status->getProcessesCount() > 0) {
$processes = $status->getProcesses();
\usort($processes, static fn (RunningProcess $a, RunningProcess $b) => $a->workerId <=> $b->workerId);

echo (new Table(indent: 1))
->setHeaderRow([
'Pid',
Expand All @@ -44,7 +47,7 @@ public function execute(Options $options): int
'Bytes (RX / TX)',
'Status',
])
->addRows(\array_map(array: $status->getProcesses(), callback: static function (RunningProcess $w) {
->addRows(\array_map(array: $processes, callback: static function (RunningProcess $w) {
return [
$w->pid,
$w->user === 'root' ? $w->user : "<color;fg=gray>{$w->user}</>",
Expand Down
1 change: 1 addition & 0 deletions src/Internal/SystemPlugin/ServerStatus/RunningProcess.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ final class RunningProcess
* @param array<int, Connection> $connections
*/
public function __construct(
public int $workerId,
public int $pid,
public string $user,
public string $name,
Expand Down
1 change: 1 addition & 0 deletions src/Internal/SystemPlugin/ServerStatus/ServerStatus.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ public function subscribeToWorkerMessages(MessageHandler $handler): void
{
$handler->subscribe(ProcessSpawnedEvent::class, weakClosure(function (ProcessSpawnedEvent $message): void {
$this->processes[$message->pid] = new RunningProcess(
workerId: $message->workerId,
pid: $message->pid,
user: $message->user,
name: $message->name,
Expand Down
1 change: 1 addition & 0 deletions src/Message/ProcessSpawnedEvent.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
final readonly class ProcessSpawnedEvent implements Message
{
public function __construct(
public int $workerId,
public int $pid,
public string $user,
public string $name,
Expand Down
1 change: 1 addition & 0 deletions src/WorkerProcess.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ private function initWorker(): void
EventLoop::onSignal(SIGUSR1, fn() => $this->reload());

$this->messageBus->dispatch(new ProcessSpawnedEvent(
workerId: $this->id,
pid: $this->pid,
user: $this->getUser(),
name: $this->name,
Expand Down

0 comments on commit 60333d2

Please sign in to comment.