Conversation
|
This wont work when your dealing with EA filecache and 2 different services, |
|
@TerraSkye, you are right, cache must use common storage only. |
added documentation
src/behaviors/StopBehavior.php
Outdated
| * @param string $id of a job | ||
| * @return bool | ||
| */ | ||
| protected function setStopping($id) |
There was a problem hiding this comment.
probably markAsStopped would be a better name.
src/behaviors/StopBehavior.php
Outdated
| */ | ||
| public $cache = 'cache'; | ||
| /** | ||
| * @var bool |
There was a problem hiding this comment.
documentation is missing, its not really clear to me what this switch is for.
There was a problem hiding this comment.
The option allows to turn off status usage that is not supported for AMQP driver.
src/behaviors/StopBehavior.php
Outdated
| public function events() | ||
| { | ||
| return [ | ||
| Queue::EVENT_BEFORE_EXEC => function (ExecEvent $event) { |
There was a problem hiding this comment.
making this a beforeExec() method instead of a closure could make it easier to extend this class.
could be added as a note to the phpdoc. |
|
How about unit tests? |
|
@samdark, tests have been added. |
cebe
left a comment
There was a problem hiding this comment.
except the naming it looks good to me.
src/stoppable/Behavior.php
Outdated
| * @author Roman Zhuravlev <zhuravljov@gmail.com> | ||
| * @since 2.0.1 | ||
| */ | ||
| class Behavior extends \yii\base\Behavior |
There was a problem hiding this comment.
imo it should be yii\queue\behaviors\Stoppable instead of yii\queue\stoppable\Behavior, Behavior as a class name does not make sense to me.
There was a problem hiding this comment.
It will be used in a configuration by long name only. As well as closure behavior. Readability shouldn't be impaired.
'queue' => [
//...
'as stoppable' => \yii\queue\stoppable\Behavior::class,
'as closure' => \yii\queue\closure\Behavior::class,
],I think to make separate behaviors namespace isn't good idea.
There was a problem hiding this comment.
It will be used in a configuration by long name only
Why do you think that people uses long names in configuration? I almost always use short names with use statements at the top of the file.
There was a problem hiding this comment.
@rob006, I'm not sure. But this make sense for config files, which cover many class definitions from different namespaces.
There was a problem hiding this comment.
Anyway, you will resolve name conflicts using namespace aliases. DbConnection, RedisConnection etc. So you can add alias:
use yii\queue\stoppable\Behavior as QueueStoppable;There was a problem hiding this comment.
I talk no about name suffix. Every package class is grouped to namespace by its role, no by class type.
This is extremely inconsistent to be honest. We have yii\queue\serializers for serializers, but doing the same for behaviors is wrong? So now we have at least three conventions for naming behaviors:
yii\queue\cli\Verbose,yii\queue\LogBehavior,yii\queue\stoppable\Behavior.
We have Interface suffix for interfaces, Event suffix for events, but name for behavior is simply random.
There was a problem hiding this comment.
We have yii\queue\serializers for serializers, but doing the same for behaviors is wrong?
Yes, because serializer implements only one role. It is queue\serializers.
Behavior is queue middleware. And behaviors can solve many different functions. queue\stoppable\Behavior allows to stop a job, queue\closure\Behavior serializes closures, queue\LogBehavior writes logs, etc.
So now we have at least three conventions for naming behaviors
I renamed Verbose to VerboseBehavior, and now we have single naming rule:
yii\queue\<Role><Type>
yii\queue\LogBehavior: Role = queue\Log, Type = Behavior
yii\queue\closure\Behavior: Role = queue\closure\, Type = Behavior
yii\queue\stoppable\Behavior: Role = stoppable\, Type = Behavior
yii\queue\PushEvent: Role = queue\Push, Type = Event
etc.
There was a problem hiding this comment.
I renamed Verbose to VerboseBehavior, and now we have single naming rule:
You clearly have two naming conventions:
yii\queue\<Role><Type>yii\queue\<role>\<Type>
Anyway, I just hate using general names for specific implementations. It kills readability and productivity. I often use "Search by class name" feature in IDE - it is useless if you name all behaviors as "Behavior". You can't just import such class because you probably will get conflicts and Behavior will be just meaningless if you find it in code.
There was a problem hiding this comment.
This is one of common ways of naming:
yii\<mode>\Applicationyii\<package>\Moduleyii\gii\generators\<entity>\GeneratorIlluminate\Redis\Connections\ConnectionIlluminate\Database\Connection<vendor>\<package>\Client
I often use "Search by class name" feature in IDE - it is useless if you name all behaviors as "Behavior".
I'm not sure about all IDEs, but PHPStorm is able to search class usage considering namespace.
There was a problem hiding this comment.
This is not a pointless discussion.
In certain discussions there is no right or wrong, just different opinions.
In this particular case, the Yii2 staff could enrich the discussion with their opinions.
In my opinion, the best solution would be to maintain the naming pattern used in Yii2.
After all, it is an extension to a larger project and here is no place to innovate.
Conflicts: CHANGELOG.md
|
I don't like this approach at all.
The exceptions here are amqp and gearman. In the cases where you use amqp / gearman and you have multiple workers, you will need a shared cache. As OP mentioned, implementing it in your own project is simple. Since this (in my opinion) is hardly ever the best, or even a good, solution I think adding this behavior will result in worse decisions by developers. |
Related #87.
The code is simple and anyone can create it inside own project.
But maybe need to create abstract class which will include stopping logics, and cache component should be moved into child?