Class: CycloneLariat::Middleware

Inherits:
Object
  • Object
show all
Defined in:
lib/cyclone_lariat/middleware.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(errors_notifier: nil, message_notifier: nil, before_save: nil, repo: Repo::InboxMessages, **options) ⇒ Middleware

Returns a new instance of Middleware.



13
14
15
16
17
18
19
# File 'lib/cyclone_lariat/middleware.rb', line 13

def initialize(errors_notifier: nil, message_notifier: nil, before_save: nil, repo: Repo::InboxMessages, **options)
  @config           = CycloneLariat::Options.wrap(options).merge!(CycloneLariat.config)
  @events_repo      = repo.new(**@config.to_h)
  @message_notifier = message_notifier
  @errors_notifier  = errors_notifier
  @before_save      = before_save
end

Instance Attribute Details

#configObject (readonly)

Returns the value of attribute config.



11
12
13
# File 'lib/cyclone_lariat/middleware.rb', line 11

def config
  @config
end

Instance Method Details

#call(_worker_instance, queue, _sqs_msg, body, &block) ⇒ Object



21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/cyclone_lariat/middleware.rb', line 21

def call(_worker_instance, queue, _sqs_msg, body, &block)
  msg = receive_message!(body)

  message_notifier&.info 'Receive message', message: msg, queue: queue
  return if msg.is_a? String

  catch_standard_error(queue, msg) do
    event = Messages::Builder.new(raw_message: msg).call

    store_in_dataset(event) do
      catch_business_error(event, &block)
    end
  end
end