D
D
Dmitriy2020-10-19 23:43:59
Laravel
Dmitriy, 2020-10-19 23:43:59

How to properly organize tasks in a queue?

The task is this:
Scrap CSV, an array of arrays is obtained.
After parsing, from this data it is necessary to create a model - Platform, then for each Platform take the API data and create SubModels with this data.

$platforms = array;
GetDataFromApi::dispatch($platforms);

In job'e, I pass the Platform via API through foreach, get a response and create a SubModel.
The problem appeared that I had a beanstalkd notfound error in the lara logs.

And there is one more idea how to do it:
$platforms;

GetDataFromApi::dispatch($platforms)
in job:
foreach ($platforms as $platform) {
     GetDataForPlatform::dispatch($platform);
}


What is the best way to solve such a problem?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
P
pLavrenov, 2020-10-27
@pLavrenov

it is best to use events
, we hang the listener on the Platform created event, add a condition to the listener under which it will work (in case, for example, some type of platform does not need to be pulled from the side) and as soon as we add it to the Platform base, it itself pushes the listener with the necessary functionality.
The event-subscriber model is generally very convenient to use almost everywhere.
laravel.com#events

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question