Skip to content

Batched jobs cannot be put on differing queues #53415

@ryangurn

Description

@ryangurn

Laravel Version

^11.9

PHP Version

8.3.13

Database Driver & Version

MariaDB

Description

Before I get started, I am not sure if this is a bug, because it is unclear if what I am trying to do is even expected, we might end up closing this saying "batches were never meant to support that" and that is fine.

I was attempting to do some job batching, in which there are two separate queues that the jobs within the batch are placed within.

For the sake of example, the two queues were "processing" and "outbound" so I can handle prioritizing this properly. I started out using sqlite for my queue and db driver, however quickly switched to mariadb.

During this process, I realized that no matter what I do when I create a batch via a hydration job, I cannot seem to get onQueue() to place the specific job into the batch but on the specified queue. Below is some example code.

Bus::batch([ (new Job1())->onQueue('processing') ])->dispatch();

at a couple points I referred to the Laravel documentation that state, "Alternatively, you may specify the job's queue by calling the onQueue method within the job's constructor:

public function __construct()
{
        $this->onQueue('processing');
}

In my specific case Job1 would hydrate the batch, with more Job1's and Job2's (which in this specific case were supposed to be on the outbound queue).

I noticed that until I stopped batching the items, I was unable to set the queue properly on items within the batch.

Steps To Reproduce

Create a batch, use a recursive job (Job 1) to hydrate the batch with more instances of itself on one queue, meanwhile in Job 1 it will also continue to hydrate the batch with another job (Job 2) but on another queue.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions