Skip to content

[9.x] Adds closure support to dispatch conditionals.#43784

Merged
taylorotwell merged 3 commits intolaravel:9.xfrom
DarkGhostHunter:feat/dispatch-condition-callable
Aug 22, 2022
Merged

[9.x] Adds closure support to dispatch conditionals.#43784
taylorotwell merged 3 commits intolaravel:9.xfrom
DarkGhostHunter:feat/dispatch-condition-callable

Conversation

@DarkGhostHunter
Copy link
Copy Markdown
Contributor

What?

Enables usage of closures to dispatch a job conditionally. The closure will receive the job arguments.

MyQueuableJob::dispatchIf(Something::check(...), $name);

Also adds tests both dispatchIf and dispatchUnless.

@taylorotwell
Copy link
Copy Markdown
Member

@DarkGhostHunter

IMO the entire job instance should be passed to the closure. I have updated the PR. Thoughts?

@DarkGhostHunter
Copy link
Copy Markdown
Contributor Author

DarkGhostHunter commented Aug 21, 2022

I don't have too much of maneuverability if I get the job instance full of non-public members, so it would force me to:

a) make a public method for additional checks.
b) make its properties public.

Since these are small chores, I can see it can be more convenient and forces me to push part of the check in the instance itself.

I approve these changes.

@taylorotwell taylorotwell merged commit 8453ed8 into laravel:9.x Aug 22, 2022
@DarkGhostHunter DarkGhostHunter deleted the feat/dispatch-condition-callable branch September 8, 2022 05:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants