I have a table users that I need to upload continuously, so once updated, I would like to relaunch the command directly.
Actually, I'm using a cron that launch itself each minute with Laravel ($schedule->command('update:users')->everyMinute();
), but I'm losing some time if the job is quicker than one minute of I will overload my server if it is more than one minute.
I was thinking to maybe use a queue, and once the script terminated, relauch itself, like this:
// Do My stuff
Queue::push(new UpdateUsers($));
But if the script crash, it will not reload itself, and I need to launch it at least once. I know that I could use a pcntl_fork function, but I would like to have a turnkey function with Laravel. How should I do ?
I would suggest running a Command the Cli, in the command place a
while (true)
loop so it will run forever. After you created this script you can run it with supervisord
this service runs the command you tell him, and when it fails it will relaunch it automaticlly. Just be aware that after X failures it will stop, it depends on how you configured it.
Example for conf file in:
/etc/supervisord/conf.d/my_infinite_script.conf
and contents could be:
[program:laravel_queue]
command=php artisan your_command:here
directory=/path/to/laravel
autostart=true
autorestart=true
stderr_logfile=/var/log/your_command.err.log
stdout_logfile=/var/log/your_command.out.log
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With