Skip to content

Commit fa6c8e3

Browse files
committed
fix factory visibilty & add bytes formater
1 parent f8c8abd commit fa6c8e3

File tree

3 files changed

+18
-2
lines changed

3 files changed

+18
-2
lines changed

src/Bytes.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,4 +42,20 @@ public static function parseFromString(string $string): self
4242

4343
return new self($number * self::SIZES[$unit]);
4444
}
45+
46+
public function formatted(): string {
47+
if ($this->bytes >= 1024 * 1024 * 1024) {
48+
return sprintf('%.1f GiB', $this->bytes / 1024 / 1024 / 1024);
49+
}
50+
51+
if ($this->bytes >= 1024 * 1024) {
52+
return sprintf('%.1f MiB', $this->bytes / 1024 / 1024);
53+
}
54+
55+
if ($this->bytes >= 1024) {
56+
return sprintf('%d KiB', $this->bytes / 1024);
57+
}
58+
59+
return sprintf('%d B', $this->bytes);
60+
}
4561
}

src/DefaultWorker.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ public function stop(): void
7979
}
8080

8181
/** @param array{runLimit?: (positive-int|null), memoryLimit?: (string|null), timeLimit?: (positive-int|null)} $options */
82-
public function create(
82+
public static function create(
8383
Closure $job,
8484
array $options,
8585
LoggerInterface $logger = new NullLogger(),

src/Listener/StopWorkerOnMemoryLimitListener.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ public function onWorkerRunning(WorkerRunningEvent $event): void
2929

3030
$this->logger?->info(
3131
'Worker stopped due to memory limit of {limit} bytes exceeded ({memory} bytes used)',
32-
['limit' => $this->memoryLimit->value(), 'memory' => $usedMemory->value()],
32+
['limit' => $this->memoryLimit->formatted(), 'memory' => $usedMemory->formatted()],
3333
);
3434

3535
$event->worker->stop();

0 commit comments

Comments
 (0)