diff --git a/src/Listeners/MonitorMasterSupervisorMemory.php b/src/Listeners/MonitorMasterSupervisorMemory.php index ebf1582f..569d5505 100644 --- a/src/Listeners/MonitorMasterSupervisorMemory.php +++ b/src/Listeners/MonitorMasterSupervisorMemory.php @@ -17,9 +17,13 @@ public function handle(MasterSupervisorLooped $event) { $master = $event->master; - if ($master->memoryUsage() > config('horizon.memory_limit', 64)) { + $memoryLimit = config('horizon.memory_limit', 64); + + if ($master->memoryUsage() > $memoryLimit) { event(new MasterSupervisorOutOfMemory($master)); + $master->output('error', 'Memory limit exceeded: Using '.ceil($master->memoryUsage()).'/'.$memoryLimit.'MB. Consider increasing horizon.memory_limit.'); + $master->terminate(12); } } diff --git a/tests/Feature/MonitorMasterSupervisorMemoryTest.php b/tests/Feature/MonitorMasterSupervisorMemoryTest.php index 362f4a4c..587f4792 100644 --- a/tests/Feature/MonitorMasterSupervisorMemoryTest.php +++ b/tests/Feature/MonitorMasterSupervisorMemoryTest.php @@ -17,6 +17,7 @@ public function test_supervisor_is_terminated_when_using_too_much_memory() $master = Mockery::mock(MasterSupervisor::class); $master->shouldReceive('memoryUsage')->andReturn(192); + $master->shouldReceive('output')->once()->with('error', 'Memory limit exceeded: Using 192/64MB. Consider increasing horizon.memory_limit.'); $master->shouldReceive('terminate')->once()->with(12); $monitor->handle(new MasterSupervisorLooped($master));