Skip to content
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

[Messenger] Add debug:messenger CLI command #26803

Merged
merged 3 commits into from
May 9, 2018
Merged

[Messenger] Add debug:messenger CLI command #26803

merged 3 commits into from
May 9, 2018

Conversation

ro0NL
Copy link
Contributor

@ro0NL ro0NL commented Apr 4, 2018

Q A
Branch? master
Bug fix? no
New feature? yes
BC breaks? no
Deprecations? no
Tests pass? yes
Fixed tickets #...
License MIT
Doc PR symfony/symfony-docs#...

Adds a debug:messenger CLI command to expose message classes that can be dispatched. Heavily inspired by debug:autowiring.

@ogizanagi
Copy link
Contributor

One less PR to do on my list :)

The tactician debug command looks like this:

Tactician routing
=================

Bus: default
------------

 ----------------------------------------------------- ----------------- 
  Command                                               Handler Service  
 ----------------------------------------------------- ----------------- 
  League\Tactician\Bundle\Tests\Fake\FakeCommand        a.handler        
  League\Tactician\Bundle\Tests\Fake\OtherFakeCommand   b.handler        
 ----------------------------------------------------- ----------------- 

https://github.com/thephpleague/tactician-bundle/blob/master/tests/Integration/DebugCommandTest.php#L37-L48

Would be great to have messages <-> handlers too here.

{
$this
->setDefinition(array(
new InputArgument('search', InputArgument::OPTIONAL, 'A search filter'),
Copy link
Contributor

@ogizanagi ogizanagi Apr 4, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not convinced this is useful until we have more info to show about a message. A simple grep is enough for this for now.

@ro0NL
Copy link
Contributor Author

ro0NL commented Apr 4, 2018

A message can have multiple handlers .. 🤔

Also the intend was concerning end users who mostly care about $bus->dispatch($whatCanIPutHere).

@ogizanagi
Copy link
Contributor

A message can have multiple handlers ..

Wasn't the case with tactician, but it's not a problem here. Just show all associated handlers.

Also the intend was concerning end users who mostly care about $bus->dispatch($whatCanIPutHere).

Would still be useful in this way :)

@nicolas-grekas nicolas-grekas added this to the 4.1 milestone Apr 5, 2018
fabpot
fabpot previously requested changes Apr 6, 2018
* file that was distributed with this source code.
*/

namespace Symfony\Bundle\FrameworkBundle\Command;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be moved to the component like the other Messenger commands.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

@ro0NL
Copy link
Contributor Author

ro0NL commented Apr 8, 2018

Latest version

image

$tableRows = array();
foreach ($this->mapping as $message => $handlers) {
$tableRows[] = array(sprintf('<fg=cyan>%s</fg=cyan>', $message));
foreach ($handlers as $handler) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that having the list of handlers in another column would make more sense and be more coherent with the rest of the debug: commands as well.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

well.. i took debug:autowring for inspiration. IMHO that one reads well :)

Also with multiple columns we probably run into a spacing issue, assuming all service IDs are FQCN.

$io = new SymfonyStyle($input, $output);

$io->title('Message Bus');
$io->text('The following classes can be dispatch:');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The following messages can be dispatched:

{
$io = new SymfonyStyle($input, $output);

$io->title('Message Bus');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Messenger

@weaverryan
Copy link
Member

I do like the table layout mentioned above #26803 (comment) - it's just a bit easier to read.

I realize that it's possible for a message to have several handlers. This is an edge-case, and I think we could handle that like this:

 ----------------------------------------------------- ----------------- 
  Command                                               Handler Service  
 ----------------------------------------------------- ----------------- 
  League\Tactician\Bundle\Tests\Fake\FakeCommand        a.handler        
                                                        c.handler        
  League\Tactician\Bundle\Tests\Fake\OtherFakeCommand   b.handler        
 ----------------------------------------------------- ----------------- 

@sroze
Copy link
Contributor

sroze commented Apr 25, 2018

This PR needs to be updated following #26864 :)

@ro0NL
Copy link
Contributor Author

ro0NL commented Apr 28, 2018

Rebased.

@sroze we cant group messages per bus as there's no such concept, so it's still a single list of messages.

@weaverryan can you update the table example with handler services like League\Tactician\Bundle\Tests\Fake\FakeCommandHandler and then tell me if 2 column layout works for you :)

@weaverryan
Copy link
Member

As we talked about, the table layout I suggested won’t work - class names are too long. So, the original format should be used, but probably with some added coloration to make it nice and clear :)

Copy link
Contributor

@sroze sroze left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good. Just two minor comments.

@@ -77,6 +77,11 @@
<tag name="console.command" command="messenger:consume-messages" />
</service>

<service id="console.command.messenger_debug" class="Symfony\Component\Messenger\Command\DebugMessengerCommand">
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All the commands are named NameDebugCommand, not DebugNameCommand. Could you change it to be something consistent with the rest?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All the commands except DebugAutowiringCommand.. which i took as a template 😅 now updated.

protected function configure()
{
$this
->setDescription('Lists classes you can dispatch using the message bus')
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suggest "message classes" or "messages" (as you say "The following messages [...]" in the output)

Copy link
Member

@chalasr chalasr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good. A functional test case would have been nice, maybe could you just share a screenshot of the final output?

@weaverryan
Copy link
Member

Here's a current screenshot, which I think looks quite good :).

screen shot 2018-05-03 at 9 06 01 am

We could perhaps do it in a different PR, but what about showing where each message is routed?

$tableRows[] = array(sprintf(' handled by %s', $handler));
}
}
$io->table(array(), $tableRows);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor, but we should print some message here if there are NO messages, like:

No messages were found that have valid handlers.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ro0NL can you update this PR at some point? Will be for beta2 now but can still be in 4.1 :)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

@sroze sroze dismissed fabpot’s stale review May 3, 2018 13:15

Changes have been made 20+ days ago :)

@nicolas-grekas nicolas-grekas changed the base branch from master to 4.1 May 7, 2018 15:06
Copy link
Member

@yceruto yceruto left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

*
* @experimental in 4.1
*/
class MessengerDebugCommand extends Command
Copy link
Member

@yceruto yceruto May 8, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't it be named DebugCommand like debug commands in other components?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point @yceruto, you are right. Commands within components' namespace are not prefixed with the component name, let's keep it this way :)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Renamed 👍

@ro0NL
Copy link
Contributor Author

ro0NL commented May 9, 2018

Thx @sroze .. still no clue about failing test :(

@ogizanagi
Copy link
Contributor

ogizanagi commented May 9, 2018

@ro0NL : deps=high failure expected. For deps=low, try updating the Framework bundle composer.json file to require symfony/messenger ~4.1-beta2

@ogizanagi
Copy link
Contributor

ogizanagi commented May 9, 2018

The -beta2 part is important, as prefer-stable and prefer-lowest is used, so it selects the released beta1 first when using just @beta

@ro0NL
Copy link
Contributor Author

ro0NL commented May 9, 2018

your're right. switched it to @dev. Not sure beta2 will resolve... :S should we try? 😓

@ogizanagi
Copy link
Contributor

That's usually what is done, so unless I'm missing something it should work: e81005e. It should resolve as far as minimum-stability allows it (which does)

@sroze
Copy link
Contributor

sroze commented May 9, 2018

Yay, and tests are all green now. Thanks @ogizanagi for the hint.

@sroze
Copy link
Contributor

sroze commented May 9, 2018

Thanks @ro0NL for working on this feature, this is much appreciated.

@sroze sroze merged commit 7f87309 into symfony:4.1 May 9, 2018
sroze added a commit that referenced this pull request May 9, 2018
…oze)

This PR was merged into the 4.1 branch.

Discussion
----------

[Messenger] Add debug:messenger CLI command

| Q             | A
| ------------- | ---
| Branch?       | master
| Bug fix?      | no
| New feature?  | yes
| BC breaks?    | no     <!-- see https://symfony.com/bc -->
| Deprecations? | no
| Tests pass?   | yes    <!-- please add some, will be required by reviewers -->
| Fixed tickets | #...   <!-- #-prefixed issue number(s), if any -->
| License       | MIT
| Doc PR        | symfony/symfony-docs#... <!-- required for new features -->

Adds a `debug:messenger` CLI command to expose message classes that can be dispatched. Heavily inspired by `debug:autowiring`.

Commits
-------

7f87309 fix deps
290c7eb Rename the command `DebugCommand`
9847b83 [Messenger] Add debug:messenger CLI command
@ro0NL ro0NL deleted the debug-messenger branch May 10, 2018 15:16
@fabpot fabpot mentioned this pull request May 21, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

9 participants