@foks So what’s the issue? You’re using a job chain, which is the appropriate solution here.
Oct 24, 2023
4
Level 15
How to make jobs run in sequence after each other?
I have a job which dispatches quite a few of another jobs. What the specific jobs do is irrelevant.
My problem is that I have a manager job, which dispatches all these jobs. The manager job gets for every user, but I cannot start processing the next manager job before all the sub-jobs dispatched by the prior manager job are completed. How would I achieve this?
The manager job has a "supervisor-job" which figures out which users need to have the manager job run on.
So the code looks something like this:
Supervisor-job handle
public function handle(): void
{
$count = count(User::list());
if (Manager::count() == $count) {
return;
}
$chain = [];
for ($i = 0; $i < $count; $i++) {
$chain[] = new ManagerJob($i);
}
Bus::chain($chain)
->dispatch();
}
ManagerJob handle
public function handle(): void
{
$chain = [];
$chain[] = new JobOne($data->one);
$chain[] = new JobTwo($data->two);
$chain[] = new JobTree($data->three);
Bus::chain($chain)
->dispatch();
}
Please or to participate in this conversation.