-
Notifications
You must be signed in to change notification settings - Fork 11.1k
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
[5.4] option to add a queue 'prefix' to all tube names #18860
Changes from 3 commits
eff266f
116cc95
17327b7
1c40e8f
6640139
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -148,7 +148,7 @@ public function deleteMessage($queue, $id) | |
*/ | ||
public function getQueue($queue) | ||
{ | ||
return $queue ?: $this->default; | ||
return $this->getQueuePrefix().($queue ?: $this->default); | ||
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 think there would be better to create method in parent class, like 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. if I'm following you correctly, the problem with moving the 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 meant a little different. I mean create new method like protected function resolveQueueName($queue) : string
{
return $this->getQueuePrefix() . ($queue ?? $this->default);
} 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. ok, i think i'm following you now. correct me if I'm wrong. the code $this->getQueuePrefix().($queue ?: $this->default) appears in 3 of the queue drivers, so you're suggesting adding a method in the parent to handle this? I agree this would work. I don't know if I see a huge benefit adding it. Might just be an additional function/layer that adds to the complexity. I'm gonna leave it as is for now, but try a PR if this gets merged. |
||
} | ||
|
||
/** | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -29,6 +29,13 @@ abstract class Queue | |
*/ | ||
protected $connectionName; | ||
|
||
/** | ||
* The queue prefix. | ||
* | ||
* @var string | ||
*/ | ||
protected $queuePrefix; | ||
|
||
/** | ||
* Push a new job onto the queue. | ||
* | ||
|
@@ -188,4 +195,27 @@ public function setContainer(Container $container) | |
{ | ||
$this->container = $container; | ||
} | ||
|
||
/** | ||
* Set the queue prefix. | ||
* | ||
* @param string $prefix | ||
* @return $this | ||
*/ | ||
public function setQueuePrefix($prefix = null) | ||
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. @browner12 Why are these not called 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 think there was a method on a parent or child class named similarly, so someone suggested it to help reduce ambiguity. |
||
{ | ||
$this->queuePrefix = $prefix; | ||
|
||
return $this; | ||
} | ||
|
||
/** | ||
* Get the queue prefix. | ||
* | ||
* @return string | ||
*/ | ||
public function getQueuePrefix() | ||
{ | ||
return $this->queuePrefix; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -152,7 +152,8 @@ protected function resolve($name) | |
|
||
return $this->getConnector($config['driver']) | ||
->connect($config) | ||
->setConnectionName($name); | ||
->setConnectionName($name) | ||
->setQueuePrefix($this->getQueuePrefix()); | ||
} | ||
|
||
/** | ||
|
@@ -232,6 +233,16 @@ public function setDefaultDriver($name) | |
$this->app['config']['queue.default'] = $name; | ||
} | ||
|
||
/** | ||
* Get the name of the queue prefix. | ||
* | ||
* @return string | ||
*/ | ||
public function getQueuePrefix() | ||
{ | ||
return isset($this->app['config']['queue.prefix']) ? $this->app['config']['queue.prefix'] : null; | ||
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. Can't we do 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. Only on master. 5.5 will be PHP 7+, this is targeting 5.4 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. yah, i had originally written 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. return 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. it appears 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.
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 don't believe I have any control over that. I'm using it identically to other places in the file. 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.
class Repository implements ArrayAccess, ConfigContract
{
.....
/**
* Get the specified configuration value.
*
* @param string $key
* @param mixed $default
* @return mixed
*/
public function get($key, $default = null)
{
return Arr::get($this->items, $key, $default);
}
.....
} 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 see what's going on. In an actual application it returns the config repository, but in the test it is returning a simple array. I've made @taylorotwell 's suggested change and updated the tests to use a config |
||
} | ||
|
||
/** | ||
* Get the full name for the given connection. | ||
* | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changing interfaces is a breaking change. I believe this should target 5.5
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ntzm since the method is in the abstract parent class, all the driver implementations will inherit it, so everything will work fine. do people define implementations that don't extend the abstract class?
on principle I agree with you. some projects seem more lax when adding new methods to the interface. can an owner comment on this?
Is the simple solution to remove it from the contract for 5.4? as I stated no one is required to use the prefix, so we'd be fine without it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes it should not be part of the contract in
5.4
, and only do so in5.5
. That how it being done before and should remain so.