Closed Jakhongir91 closed 3 years ago
Thank you!
Thank you for this option, but the default value of 30 is not optimal. Better to have the standard behavior, if the parameter is not set: "run forever"!
And a note in the README about the 30 seconds in production is missing!
@bushbill I'll remove the bit that sets the default in production.
Closes issue #17
What has been done (and why) A lifetime of short schedule's worker has been added to mitigate RAM leaks when running frequent processes every seconds with allowing overlapping.
How does it work A new property
$lifetime
was added inSpatie\ShortSchedule\ShortSchedule
class. InShortSchedule
class in run method, after adding every scheduled task to loop it will check if the lifetime property is set and if it was, it will add event loop termination. The default lifetime for production environment is 30 seconds For dev mode there is not lifetime constraint, to make it possible to runphp artisan short-schedule:run
command in console without auto exiting, when developing and testing features locally.How to test
Set 5 short scheduled tasks in
App\Console\Kernel.php
with frequency of 1 second, don't usewithoutOverlapping()
method.When running in non production mode (APP_ENV=local in .env file), execute in console
php artisan short-schedule:run --lifetime=5
. After each task will be executed once, the worker will terminate itself and all memory will be dismissed at once.When running in production mode (APP_ENV=production in .env file) configure supervisor to run
php artisan short-schedule:run
. Then the worker will terminate itself each 5 seconds and supervisor will bring it back.Tests At the moment I do not know how to create autotests for this PR