Class: WaterDrop::Instrumentation::Callbacks::OauthbearerTokenRefresh

Inherits:
Object
  • Object
show all
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

Constructor Details

#initialize(bearer, monitor) ⇒ OauthbearerTokenRefresh

Returns a new instance of OauthbearerTokenRefresh.

Parameters:

  • bearer (Rdkafka::Producer)

    given rdkafka instance. It is needed as we need to have a reference to call ‘#oauthbearer_set_token` or `#oauthbearer_set_token_failure` upon the event.

  • monitor (WaterDrop::Instrumentation::Monitor)

    monitor we are using



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` 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.

Parameters:

  • _rd_config (Rdkafka::Config)
  • bearer_name (String)

    name of the bearer for which we refresh



26
27
28
29
30
31
32
33
34
# 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
  )
end