How do I postpone work in Laravel 5.2?

Let's say my server sends an identical request to 5 client devices at 12:00:05. I want to wait 90 seconds (until 12:01:35), and then check which clients answered the request accordingly and do some other things. What is the best way to accomplish something like this?

Should I queue a job and use sleep(90)at the beginning? The problem is that a job of this type will always take at least 90 seconds, and the default server is installed after 60 seconds. I believe that I can change the server settings, but my other jobs are still considered timed if they pass after 60 seconds.

Should I queue a scheduled task? The problem here is that I think Laravel and cron give you accurate accuracy until the next minute (12:01 or 12:02, but not 12:01:35).

+4
source share
1 answer

You can use delayed sending for your queues in Laravel. https://laravel.com/docs/master/queues#delayed-dispatching

$job = (new YourEvent($coolEvent))->delay(Carbon::now()->addSeconds(90));

This will start the task 90 seconds after it is added to the queue.

+5
source

Source: https://habr.com/ru/post/1655128/


All Articles