Answer the question
In order to leave comments, you need to log in
How to receive an event after executing a group of parallel jobs in Laravel Jobs?
Used Laravel 6
Example:
Get product offers from 10 vendors via API.
Each request is a separate task.
It is necessary to execute requests in parallel, and after all requests are completed, process and give to the user.
The problem is getting the event of successful completion of all subtasks.
Answer the question
In order to leave comments, you need to log in
Trite and just not inventing anything!
Task - getting 10 responses
Subtask - processing 1 response
Sending a request for product offers - created 10 rows in the database:
| id | task_id | provider_id | response |
We send requests with unique id, we are waiting for them in response + the response itself.
When we receive a response, we write it to the database, in the response field.
We check the response field for NULL, if there is, then we do nothing, if not, then we must send it to the user.
1) async version
The simplest - https://amphp.org/artax/
A little more control - https://ampp.org/parallel-functions/
A little more control - https://github.com/ampp/parallel
Nuance in that this is not the easiest thing in terms of debugging and its support is so-so. Yes, it works, yes, it is covered with tests, yes, it is supported, but you cannot fix any non-standard garbage and fix anything yourself.
2) option with preparing data before user request - if possible
3) shit-option - your decision. Drive into the base / radish and count how much is left there, pulling the status every 500ms.
I didn’t quite understand what the problem is with the end of the workers - put everything in the job chain, or lock on the necessary keys with redis::funnel, or lock with the base. It is not entirely clear what exactly the task is, along with all its nuances.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question