-
Notifications
You must be signed in to change notification settings - Fork 11.8k
[13.x] Add ability to default queue by class type #58094
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
+562
−19
Merged
Changes from all commits
Commits
Show all changes
37 commits
Select commit
Hold shift + click to select a range
815c3ab
default queue by class
jackbayliss e5b1903
rename bits and work on comments
jackbayliss 8bf8cd0
remove alias
jackbayliss 568cdb2
quick adjustment
jackbayliss b037454
change to route over default
jackbayliss a95246a
and.. dont forget the tests
jackbayliss 975ac2a
tweak comments
jackbayliss da07f6f
order provides
jackbayliss 9761c73
test
jackbayliss 4982762
sprinkle some laravel terms
jackbayliss 09b75b4
Revert "sprinkle some laravel terms"
jackbayliss bf889aa
Reapply "sprinkle some laravel terms"
jackbayliss 0e0dcea
final test tweaks
jackbayliss acad1e9
Update QueueServiceProvider.php
jackbayliss 142c03a
formatting
taylorotwell 0d31451
fix variable
taylorotwell badb71e
change this method
jackbayliss d28e7af
move file / dependency
taylorotwell 812b8f2
Merge branch '13.x-queue-by-class' of github.com:jackbayliss/framewor…
taylorotwell 2ddd154
fix tests
taylorotwell a8789e5
add support for broadcast events
taylorotwell 1fe92e2
add support for routing connection
taylorotwell bd666b4
update signature
taylorotwell d8a42ca
Improve test
jackbayliss 2b39b78
cs
jackbayliss f5b17f5
Apply resolveConnectionFromQueueRoute
jackbayliss e0d5383
Update QueueManager.php
jackbayliss d4ffa21
improve test
jackbayliss c1de15e
fix le tests
jackbayliss 6a3aff7
and this test..
jackbayliss 5bc5521
more test tweaks and fixes
jackbayliss 3f77dbb
improve tests, add broadcast test
jackbayliss 0f0142e
Add event dispatcher test
jackbayliss fe9b398
typo
jackbayliss a7e7e3b
cs
jackbayliss 1a5af26
ensure instance is nulled after
jackbayliss 467cf26
formatting
taylorotwell File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -5,13 +5,16 @@ | |||||
| use Closure; | ||||||
| use Illuminate\Contracts\Queue\Factory as FactoryContract; | ||||||
| use Illuminate\Contracts\Queue\Monitor as MonitorContract; | ||||||
| use Illuminate\Support\Queue\Concerns\ResolvesQueueRoutes; | ||||||
| use InvalidArgumentException; | ||||||
|
|
||||||
| /** | ||||||
| * @mixin \Illuminate\Contracts\Queue\Queue | ||||||
| */ | ||||||
| class QueueManager implements FactoryContract, MonitorContract | ||||||
| { | ||||||
| use ResolvesQueueRoutes; | ||||||
|
|
||||||
| /** | ||||||
| * The application instance. | ||||||
| * | ||||||
|
|
@@ -120,6 +123,19 @@ public function stopping($callback) | |||||
| $this->app['events']->listen(Events\WorkerStopping::class, $callback); | ||||||
| } | ||||||
|
|
||||||
| /** | ||||||
| * Set the queue route for the given class. | ||||||
| * | ||||||
| * @param array|class-string $class | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You can type the array as well:
Suggested change
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'll let Big T decide on that one 👍🏻 |
||||||
| * @param string|null $queue | ||||||
| * @param string|null $connection | ||||||
| * @return void | ||||||
| */ | ||||||
| public function route(array|string $class, $queue = null, $connection = null) | ||||||
| { | ||||||
| $this->queueRoutes()->set($class, $queue, $connection); | ||||||
| } | ||||||
|
|
||||||
| /** | ||||||
| * Determine if the driver is connected. | ||||||
| * | ||||||
|
|
||||||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,106 @@ | ||
| <?php | ||
|
|
||
| namespace Illuminate\Queue; | ||
|
|
||
| class QueueRoutes | ||
| { | ||
| /** | ||
| * The mapping of class names to their default routes. | ||
| * | ||
| * @var array<class-string, string> | ||
| */ | ||
| protected $routes = []; | ||
|
|
||
| /** | ||
| * Get the queue connection that a given queueable instance should be routed to. | ||
| * | ||
| * @param object $queueable | ||
| * @return string|null | ||
| */ | ||
| public function getConnection($queueable) | ||
| { | ||
| $route = $this->getRoute($queueable); | ||
|
|
||
| if (is_null($route)) { | ||
| return; | ||
| } | ||
|
|
||
| return is_string($route) | ||
| ? $route | ||
| : $route[0]; | ||
| } | ||
|
|
||
| /** | ||
| * Get the queue that a given queueable instance should be routed to. | ||
| * | ||
| * @param object $queueable | ||
| * @return string|null | ||
| */ | ||
| public function getQueue($queueable) | ||
| { | ||
| $route = $this->getRoute($queueable); | ||
|
|
||
| if (is_null($route)) { | ||
| return; | ||
| } | ||
|
|
||
| return is_string($route) | ||
| ? $route | ||
| : $route[1]; | ||
| } | ||
|
|
||
| /** | ||
| * Get the queue that a given queueable instance should be routed to. | ||
| * | ||
| * @param object $queueable | ||
| * @return string|null | ||
| */ | ||
| public function getRoute($queueable) | ||
| { | ||
| if (empty($this->routes)) { | ||
| return null; | ||
| } | ||
|
|
||
| $classes = array_merge( | ||
| [get_class($queueable)], | ||
| class_parents($queueable) ?: [], | ||
| class_implements($queueable) ?: [], | ||
| class_uses_recursive($queueable) | ||
| ); | ||
|
|
||
| foreach ($classes as $class) { | ||
| if (isset($this->routes[$class])) { | ||
| return $this->routes[$class]; | ||
| } | ||
| } | ||
|
|
||
| return null; | ||
| } | ||
|
|
||
| /** | ||
| * Register the queue route for the given class. | ||
| * | ||
| * @param array|class-string $class | ||
| * @param string|null $queue | ||
| * @param string|null $connection | ||
| * @return void | ||
| */ | ||
| public function set(array|string $class, $queue = null, $connection = null) | ||
| { | ||
| $routes = is_array($class) ? $class : [$class => [$connection, $queue]]; | ||
|
|
||
| foreach ($routes as $from => $to) { | ||
| $this->routes[$from] = $to; | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * Get all registered queue routes. | ||
| * | ||
| * @return array | ||
| */ | ||
| public function all() | ||
| { | ||
| return $this->routes; | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.