Skip to content

Commit 0bb7462

Browse files
[5.x] Store memory used when dispatching SupervisorOutOfMemory (#1550)
* Update MonitorSupervisorMemory.php * add getters/setters * Update SupervisorOutOfMemory.php * Update SupervisorOutOfMemory.php --------- Co-authored-by: Taylor Otwell <[email protected]>
1 parent 8b02985 commit 0bb7462

File tree

2 files changed

+32
-2
lines changed

2 files changed

+32
-2
lines changed

src/Events/SupervisorOutOfMemory.php

+30
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,13 @@ class SupervisorOutOfMemory
1313
*/
1414
public $supervisor;
1515

16+
/**
17+
* The memory usage that exceeded the allowable limit.
18+
*
19+
* @var int|float
20+
*/
21+
public $memoryUsage;
22+
1623
/**
1724
* Create a new event instance.
1825
*
@@ -23,4 +30,27 @@ public function __construct(Supervisor $supervisor)
2330
{
2431
$this->supervisor = $supervisor;
2532
}
33+
34+
/**
35+
* Get the memory usage that triggered the event.
36+
*
37+
* @return int|float
38+
*/
39+
public function getMemoryUsage()
40+
{
41+
return $this->memoryUsage ?? $this->supervisor->memoryUsage();
42+
}
43+
44+
/**
45+
* Set the memory usage that was recorded when the event was dispatched.
46+
*
47+
* @param int|float $memoryUsage
48+
* @return $this
49+
*/
50+
public function setMemoryUsage($memoryUsage)
51+
{
52+
$this->memoryUsage = $memoryUsage;
53+
54+
return $this;
55+
}
2656
}

src/Listeners/MonitorSupervisorMemory.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ public function handle(SupervisorLooped $event)
1717
{
1818
$supervisor = $event->supervisor;
1919

20-
if ($supervisor->memoryUsage() > $supervisor->options->memory) {
21-
event(new SupervisorOutOfMemory($supervisor));
20+
if (($memoryUsage = $supervisor->memoryUsage()) > $supervisor->options->memory) {
21+
event((new SupervisorOutOfMemory($supervisor))->setMemoryUsage($memoryUsage));
2222

2323
$supervisor->terminate(12);
2424
}

0 commit comments

Comments
 (0)