R
R
Roman Sarvarov2021-09-24 10:01:48
Laravel
Roman Sarvarov, 2021-09-24 10:01:48

How to organize a parser using queues in Laravel Horizon?

I am using Laravel Horizon.
Imagine that there are 20 sites that you need to go through all of them in + -1 hour, scan and save the results in the database. How it is competent to organize through queues?
You need to make sure that the tasks for each site should go in turn. If there are several sites in the queue at the same time, each site has its own queue (if site 1 is being scanned and site 2 is being added at the same time, there should be no stops in scanning site 1). In order not to "ddos" sites, it is necessary that the tasks are performed at some interval, it is desirable to distribute them evenly within an hour.
I thought to do it like this:
1. Make cron to start Batch (Bus::batch()) tasks and distribute these 20 sites over the course of an hour (every ~3 minutes).
2. Each site has its own queue. Those. in horizon.php in the supervozor settings it will be like this:

'queue' => ['site1', 'site2', 'site3' /* ... */, 'site20'],
'balance' => 'auto',
'maxProcesses' => 20, // количество сайтов


Or is there a smarter way to do this?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
J
JhaoDa, 2021-09-24
@megakor

First, you are confusing the concept of "queue" and "task in the queue".
Secondly, it is necessary not to invent some kind of crutches on the crown, but to start reading the documentation. There and about the division into different queues, and about the limitation of the simultaneously executed number of tasks, and about the intervals between the execution of tasks, and much more.
In short: you create 20 queues, each with one worker with the parameter --sleep=1.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question