Class: CycloneLariat::Outbox

Inherits:
Object
  • Object
show all
Extended by:
Configurable, Loadable
Includes:
LunaPark::Extensions::Injector
Defined in:
lib/cyclone_lariat/plugins/outbox.rb,
lib/cyclone_lariat/plugins/outbox/loadable.rb,
lib/cyclone_lariat/plugins/outbox/configurable.rb,
lib/cyclone_lariat/plugins/outbox/repo/messages.rb,
lib/cyclone_lariat/plugins/outbox/services/resend.rb,
lib/cyclone_lariat/plugins/outbox/mappers/messages.rb,
lib/cyclone_lariat/plugins/outbox/repo/sequel/messages.rb,
lib/cyclone_lariat/plugins/outbox/extensions/sequel_outbox.rb,
lib/cyclone_lariat/plugins/outbox/repo/active_record/messages.rb,
lib/cyclone_lariat/plugins/outbox/extensions/active_record_outbox.rb

Defined Under Namespace

Modules: Configurable, Extensions, Loadable, Mappers, Repo, Services

Constant Summary

Constants included from Configurable

Configurable::CONFIG_ATTRS

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Configurable

configure

Methods included from Loadable

load

Constructor Details

#initializeOutbox

Returns a new instance of Outbox.



22
23
24
# File 'lib/cyclone_lariat/plugins/outbox.rb', line 22

def initialize
  @messages = []
end

Instance Attribute Details

#messagesObject (readonly)

Returns the value of attribute messages.



20
21
22
# File 'lib/cyclone_lariat/plugins/outbox.rb', line 20

def messages
  @messages
end

Instance Method Details

#<<(message) ⇒ Object



40
41
42
43
# File 'lib/cyclone_lariat/plugins/outbox.rb', line 40

def <<(message)
  message.uuid = repo.create(message)
  messages << message
end

#publishObject



26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/cyclone_lariat/plugins/outbox.rb', line 26

def publish
  sent_message_uids = messages.each_with_object([]) do |message, sent_message_uuids|
    begin
      sns_client.publish message, fifo: message.fifo?
      sent_message_uuids << message.uuid
    rescue StandardError => e
      repo.update_error(message.uuid, e.message)
      config.on_sending_error&.call(message, e)
      next
    end
  end
  repo.delete(sent_message_uids) unless sent_message_uids.empty?
end

#push(message) ⇒ Object



45
46
47
# File 'lib/cyclone_lariat/plugins/outbox.rb', line 45

def push(message)
  self << message
end