Class: Gcpc::Subscriber::HandleEngine

Inherits:
Object
  • Object
show all
Defined in:
lib/gcpc/subscriber/handle_engine.rb

Overview

HandleEngine handle messages and exceptions with interceptors.

Instance Method Summary collapse

Constructor Details

#initialize(handler:, interceptors:) ⇒ HandleEngine

Returns a new instance of HandleEngine.

Parameters:



7
8
9
10
# File 'lib/gcpc/subscriber/handle_engine.rb', line 7

def initialize(handler:, interceptors:)
  @handler      = (handler.class == Class) ? handler.new : handler
  @interceptors = interceptors.map { |i| (i.class == Class) ? i.new : i }
end

Instance Method Details

#handle(message) ⇒ Object

Parameters:

  • message (Google::Cloud::Pubsub::ReceivedMessage)


13
14
15
16
17
18
19
20
# File 'lib/gcpc/subscriber/handle_engine.rb', line 13

def handle(message)
  d = message.data.dup
  a = message.attributes.dup

  intercept_message!(@interceptors, d, a, message) do |dd, aa, m|
    handle_message(dd, aa, m)
  end
end

#on_error(error) ⇒ Object

Parameters:

  • error (Exception)


23
24
25
26
27
# File 'lib/gcpc/subscriber/handle_engine.rb', line 23

def on_error(error)
  intercept_error!(@interceptors, error) do |e|
    handle_on_error(e)
  end
end