-
Notifications
You must be signed in to change notification settings - Fork 29
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
Question / feature request: hooks around call? #111
Comments
Hi there! I’m afraid there’s currently no built-in instrumentation or hooks. You could try and override the class ApplicationActor
def _call
ActiveSupport::Notifications.instrument("ApplicationActor", extra: self) do
super
end
end
end I’d be happy to accept a pull-request to add ActiveSupport instrumentation to actor-rails or some kind of hook syntax such as |
Thank you for your feedback @sunny - I'll think about proposing something to you. |
I don't have a good solution for now to avoid using the private interface method Currently I'm following the @sunny hint. # app/lib/instrumentable_actor.rb
module InstrumentableActor
# NOTE: rely on a private method _call
def _call(**_args)
extra = { class: self.class, args: result.to_h }
ActiveSupport::Notifications.instrument("ApplicationActor", extra:) do
super
end
end
end
# app/actors/application_actor.rb
class ApplicationActor
include ServiceActor::Base
include InstrumentableActor
end
# config/initializers/notifications.rb
ActiveSupport::Notifications.subscribe("ApplicationActor") do |event, start, finish, id, payload|
Rails.logger.info do
extra = payload[:extra]
"[#{id}] #{event} - #{extra[:class]} #{extra[:args]} - start: #{start} - finish: #{finish}"
end
end The logs have this form:
|
Perhaps the Would you be willing to try a pull-request over there with that change? |
Hey @sunny. |
I think it’s fine for Another option would be to introduce a callback mechanic in |
Hey :)
I wonder if there is a way to execute some callback code before / after / around the call method of an actor.
My use case is the following:
ApplicationActor
(which simply hasinclude ServiceActor::Base
)I tried to add to
ApplicationActor
the following:but it gets executed only on the call of the "main" actor.
Any idea?
The text was updated successfully, but these errors were encountered: