Skip to content

Commit

Permalink
Add events for when supervisors are terminated (#1282)
Browse files Browse the repository at this point in the history
* Add events for when supervisors are terminated

* Fix styleCI issues

* rename files

* Update SupervisorOutOfMemory.php

---------

Co-authored-by: Taylor Otwell <taylor@laravel.com>
  • Loading branch information
PrinsFrank and taylorotwell committed Jun 8, 2023
1 parent 6ee1123 commit 48e842d
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 0 deletions.
26 changes: 26 additions & 0 deletions src/Events/MasterSupervisorOutOfMemory.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?php

namespace Laravel\Horizon\Events;

use Laravel\Horizon\MasterSupervisor;

class MasterSupervisorOutOfMemory
{
/**
* The master supervisor instance.
*
* @var \Laravel\Horizon\MasterSupervisor
*/
public $master;

/**
* Create a new event instance.
*
* @param \Laravel\Horizon\MasterSupervisor $master
* @return void
*/
public function __construct(MasterSupervisor $master)
{
$this->master = $master;
}
}
26 changes: 26 additions & 0 deletions src/Events/SupervisorOutOfMemory.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?php

namespace Laravel\Horizon\Events;

use Laravel\Horizon\Supervisor;

class SupervisorOutOfMemory
{
/**
* The supervisor instance.
*
* @var \Laravel\Horizon\Supervisor
*/
public $supervisor;

/**
* Create a new event instance.
*
* @param \Laravel\Horizon\Supervisor $supervisor
* @return void
*/
public function __construct(Supervisor $supervisor)
{
$this->supervisor = $supervisor;
}
}
3 changes: 3 additions & 0 deletions src/Listeners/MonitorMasterSupervisorMemory.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace Laravel\Horizon\Listeners;

use Laravel\Horizon\Events\MasterSupervisorLooped;
use Laravel\Horizon\Events\MasterSupervisorOutOfMemory;

class MonitorMasterSupervisorMemory
{
Expand All @@ -18,6 +19,8 @@ public function handle(MasterSupervisorLooped $event)

if ($master->memoryUsage() > config('horizon.memory_limit', 64)) {
$master->terminate(12);

event(new MasterSupervisorOutOfMemory($master));
}
}
}
3 changes: 3 additions & 0 deletions src/Listeners/MonitorSupervisorMemory.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace Laravel\Horizon\Listeners;

use Laravel\Horizon\Events\SupervisorLooped;
use Laravel\Horizon\Events\SupervisorOutOfMemory;

class MonitorSupervisorMemory
{
Expand All @@ -18,6 +19,8 @@ public function handle(SupervisorLooped $event)

if ($supervisor->memoryUsage() > $supervisor->options->memory) {
$supervisor->terminate(12);

event(new SupervisorOutOfMemory($supervisor));
}
}
}

0 comments on commit 48e842d

Please sign in to comment.