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).