T
T
Troodi Larson2020-09-01 23:16:24
Message Queues
Troodi Larson, 2020-09-01 23:16:24

What is the best method to process the task in exactly N seconds (milliseconds)?

Good evening. It is necessary to execute the task exactly N seconds after dispatch. There can be a lot of tasks from a hundred to a potential million per second with work through redis. The standard $job->delay(5) can be executed even after 7 seconds or more, but it is important to execute it exactly after 5 seconds. I so understand by means of queues of the given result to achieve most likely it is impossible. And an alternative option would be an infinite loop with asynchronous execution of tasks.

I would like to hear your thoughts on this matter. Thank you in advance!

Answer the question

In order to leave comments, you need to log in

3 answer(s)
D
Darkhan Kamaliev, 2020-09-01
@darakanoit

Did you run 1 process to process the queues?
If I'm not mistaken, then you can run the required number of workers and they will immediately sort out the tasks.
And in theory (if I'm right of course), you can make N number of workers to cover X of your tasks and they will be executed at the specified time, because there will always be a free worker .. but how many of them you need is another matter.
And so maybe you should smoke reactphp and maybe there are some implementations in the stall.
For example https://github.com/spatie/laravel-cronless-schedule
Judging by the description, it allows every 5 seconds (below in the readme) to check tasks similar to cron. Again, in theory, set a timer to check tasks every second and execute them.
As a 3rd option, look at third-party queues (on other PLs) that could cover your tasks.
The message in which direction to smoke, I hope I gave it.

K
Korya, 2020-09-10
@Korya

#!/bin/bash

while true; do
  # Do something (php artisan queue:work --once)
  sleep 5;
done

As an option, and in the supervisor it's all.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question