Home > front end >  How to run command after hours from controller action in laravel?
How to run command after hours from controller action in laravel?

Time:07-12

I need to notify users of incoming end time of created data. Let's say need to notify the users after 3hrs of created data. But I dont want to run cron job every hour because this will slow down the system.

CodePudding user response:

You can queue a command then add a delay to it.

use Illuminate\Support\Facades\Artisan;

Artisan::queue('your:command')->delay(60 * 60 * 3);

I haven't tried to delay a queue for hours. That's why I think a scheduled task is more reliable as you know the time when it runs.

CodePudding user response:

Laravel has a Task Scheduler pretty efficient to work with cron. You only have to configure it once to run once a minute and Laravel does the rest for checking when it needs to run. The syntax is pretty simple and you find all available configurations on your codebase.

https://laravel.com/docs/9.x/scheduling

This hardly slows down the system since Laravel only runs the necessary.

  • Related