How to make a video:

Video question

In case the video becomes unavailable: There is a database. It contains group IDs. In each iteration, the loop passes the group ID to the function. The function starts to fulfill various conditions, requests, records in the database. This takes the Nth amount of time. And so on each iteration.

This method is consistent.

How to make it so that the IDs of the groups would first be loaded, and then the execution of the functions started simultaneously.

Closed due to the fact that off-topic participants 0xdb , HamSter , Enikeyschik , Dmitry Kozlov , aleksandr barakin Dec 29, '18 at 9:34 .

It seems that this question does not correspond to the subject of the site. Those who voted to close it indicated the following reason:

  • “Questions asking for help with debugging (“ why does this code not work? ”) Should include the desired behavior, a specific problem or error, and a minimum code for playing it right in the question . Questions without an explicit description of the problem are useless for other visitors. See How to create minimal, self-sufficient and reproducible example . " - 0xdb, HamSter, Dmitry Kozlov, aleksandr barakin
If the question can be reformulated according to the rules set out in the certificate , edit it .

  • 6
    Attention to the screen! Video question! - cpp questions
  • @cppquestions So what’s wrong? :) - Dmitry Movsesyan
  • The question must be in text form. Describe your problem in as much detail as possible, preferably with a code. If this is not enough, give a link to the video - cpp questions as an additional source.
  • @cppquestions Why are these restrictions, I decided that on the video about the question I will explain more if I would do it in text format. - Dmitry Movsesyan
  • 2
    In addition, questions consisting of "how to make an X + link" are of no benefit to the community. The link will become inactive after some time, and the question will become absolutely useless - cpp questions

1 answer 1

I really wanted to make a video response, but now, unfortunately, there is no such possibility. So just write.

As you probably noticed yourself, you have two tasks: creating a queue and processing the tasks of this queue. There are various tools for solving them, but I suggest making your bike so that, having figured out how it works, make an informed choice (and maybe ride this bike and go).

Step 1: Create a queue of tasks to execute.

We use the database (you already have it, you do not need to install anything else). We add there a simple table with tasks with fields the состояние выполнения данные для задачи .

Now select group IDs and create a new entry for each in the queue table.

Step 2: Rough up the queue queue.

Every five seconds we run a script worker (or several, using xargs -P , for example), which climbs into the database and selects one entry from the queue and marks it as a task в процессе выполнения . If there are no free tasks in the queue, the script simply ends. If you manage to get the task, the script starts to perform it (pull third-party api, write something to the database, process pictures, etc.). It is important not to allow two simultaneously launched scripts to start working on the same task. To do this, use your obd lock. Upon completion of the task, it can be marked as выполнена or deleted.

This solution shows the general principle of operation of such systems. In any case, you need a queue (in this case, the table in the database) and a demon that rakes it (in this case, kron).