consil
1 month ago

Job dispatch options - how does this actually work?

Posted 1 month ago by consil

This is something I am trying to wrap my head around, and I'm sure I am simply missing something really simple.

I can dispatch a job like this:

dispatch(new MyJob());

That dispatches to the default connector and queue (assuming the job itself does not fiddle with those details).

I can also add some options:

dispatch(new MyJob())->onConnection('database');

and more:

dispatch(new MyJob())->onConnection('database')->onQueue('fast-queue');

So, each option that is added, returns either a new object or updates the queue object. That makes sense.

What I don't understand, is at what point the job actually gets queued. There is no final "do it now" method like there is for eloquent (e.g. ->save() or ->get()). So when does the music stop with this one? How do I actually get to keep adding options before the job finally ends up on the queue. What puts it onto the queue - is it the destructor of the app maybe? Puzzled.

Please sign in or create an account to participate in this conversation.