Class: WaterDrop::Instrumentation::Callbacks::OauthbearerTokenRefresh
- Inherits:
-
Object
- Object
- WaterDrop::Instrumentation::Callbacks::OauthbearerTokenRefresh
- Defined in:
- lib/waterdrop/instrumentation/callbacks/oauthbearer_token_refresh.rb
Overview
Callback that is triggered when oauth token needs to be refreshed.
Instance Method Summary collapse
-
#call(_rd_config, bearer_name) ⇒ Object
Upon receiving of this event, user is required to invoke either
#oauthbearer_set_token
or#oauthbearer_set_token_failure
on theevent[:bearer]
depending whether token obtaining was successful or not. -
#initialize(bearer, monitor) ⇒ OauthbearerTokenRefresh
constructor
A new instance of OauthbearerTokenRefresh.
Constructor Details
#initialize(bearer, monitor) ⇒ OauthbearerTokenRefresh
Returns a new instance of OauthbearerTokenRefresh.
12 13 14 15 |
# File 'lib/waterdrop/instrumentation/callbacks/oauthbearer_token_refresh.rb', line 12 def initialize(bearer, monitor) @bearer = bearer @monitor = monitor end |
Instance Method Details
#call(_rd_config, bearer_name) ⇒ Object
Upon receiving of this event, user is required to invoke either #oauthbearer_set_token
or #oauthbearer_set_token_failure
on the event[:bearer]
depending whether token obtaining was successful or not.
Please refer to WaterDrop and Karafka documentation or Rdkafka::Helpers::OAuth
documentation directly for exact parameters of those methods.
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/waterdrop/instrumentation/callbacks/oauthbearer_token_refresh.rb', line 26 def call(_rd_config, bearer_name) return unless @bearer.name == bearer_name @monitor.instrument( 'oauthbearer.token_refresh', bearer: @bearer, caller: self ) # This runs from the rdkafka thread, thus we want to safe-guard it and prevent absolute # crashes even if the instrumentation code fails. If it would bubble-up, it could crash # the rdkafka background thread rescue StandardError => e @monitor.instrument( 'error.occurred', caller: self, error: e, producer_id: @producer_id, type: 'callbacks.oauthbearer_token_refresh.error' ) end |