Skip to content

Conversation

mwear
Copy link
Contributor

@mwear mwear commented Feb 16, 2016

It would be nice for ActionCable::Channel::Base#perform_action to have an ActiveSupport::Notifications instrumentation hook similar to ActionController#process_action
This PR adds an ActiveSupport::Notification hook to ActionCable Channel::Base#perform_action. The payload contains the action and the data passed to perform action.

@rails-bot
Copy link

Thanks for the pull request, and welcome! The Rails team is excited to review your changes, and you should hear from @rafaelfranca (or someone else) soon.

If any changes to this PR are deemed necessary, please add them as extra commits. This ensures that the reviewer can see what has changed since they last reviewed the code. Due to the way GitHub handles out-of-date commits, this should also make it reasonably obvious what issues have or haven't been addressed. Large or tricky changes may require several passes of review and changes.

Please see the contribution instructions for more information.

dispatch_action(action, data)
else
logger.error "Unable to process #{action_signature(action, data)}"
ActiveSupport::Notifications.instrument("perform_action.action_cable", action: action, data: data) do
Copy link
Contributor

Choose a reason for hiding this comment

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

This should go inside the conditional, right above the dispatch method. Wouldn't we only want to send out notifications for actions that can be processed?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's updated. Thanks for pointing that out!

@rafaelfranca
Copy link
Member

Since you are here could you do the same in the transmit* calls? and move the logger.info calls to a LogSubscriber?

@mwear
Copy link
Contributor Author

mwear commented Feb 17, 2016

Sure, I'd be happy to @rafaelfranca.

@rafaelfranca
Copy link
Member

Thank you so much!

@@ -166,6 +166,21 @@ def rm_rf
end
end

test "notification for perform_action" do
events = []
ActiveSupport::Notifications.subscribe "perform_action.action_cable" do |*args|
Copy link
Member

Choose a reason for hiding this comment

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

We need to unsubscribe in a ensure block.

@mwear mwear force-pushed the action_cable_notifications branch from 9163fa7 to 0d1972c Compare February 17, 2016 23:10
@mwear
Copy link
Contributor Author

mwear commented Feb 18, 2016

It appears that the last commit did not trigger CI for some reason. The transmit* methods are instrumented and there is now a LogSubscriber for ActionCable::Channel. This is ready for feedback at your convenience.

@maclover7
Copy link
Contributor

Can you squash down your commits?

@mwear mwear force-pushed the action_cable_notifications branch 6 times, most recently from 33e9029 to 040a462 Compare February 20, 2016 00:36
@rafaelfranca rafaelfranca added this to the 5.0.0 milestone Feb 20, 2016
@rafaelfranca
Copy link
Member

Awesome work!

@mwear mwear force-pushed the action_cable_notifications branch 3 times, most recently from 136f4ec to 9c1dd02 Compare February 25, 2016 02:41
@@ -160,7 +161,10 @@ def perform_action(data)
action = extract_action(data)

if processable_action?(action)
dispatch_action(action, data)
payload = {channel_class: self.class.name, action: action, data: data}
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you add spaces and after the brackets?

{ channel_class: self.class.name, action: action, data: data }

@maclover7
Copy link
Contributor

A few small code styling comments, otherwise this looks really good! :)

@mwear mwear force-pushed the action_cable_notifications branch from 9c1dd02 to 27011da Compare February 25, 2016 06:42
@mwear
Copy link
Contributor Author

mwear commented Feb 25, 2016

Thanks for the feedback! I've updated the PR with your comments.

This commit adds ActiveSupport::Notifications instrumentation hooks
and a LogSuscriber to ActionCable::Channel::Base.
@mwear mwear force-pushed the action_cable_notifications branch from 27011da to 09a1321 Compare March 4, 2016 22:48
@mwear
Copy link
Contributor Author

mwear commented Mar 24, 2016

@rafaelfranca I was wondering if this is still targeted for 5.0.0?

@rafaelfranca
Copy link
Member

Yes it is. I found some problems with how Action Cable logging interact with tagged logs and how it would work with the LoggerSubscriber and I was going to address it before merging. I probably will do it tomorrow.

@mwear
Copy link
Contributor Author

mwear commented Mar 24, 2016

Great, thanks for the update!

rafaelfranca added a commit that referenced this pull request Mar 30, 2016
Add ActiveSupport::Notification to Channel::Base#perform_action
@rafaelfranca rafaelfranca merged commit 09a1321 into rails:master Mar 30, 2016
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.

4 participants