Module: HermesMessengerOfTheGods::Concerns::Message

Extended by:
ActiveSupport::Concern
Includes:
ActiveModel::Model, EndpointBuilder::Helpers, LoggingHelpers
Defined in:
lib/hermes_messenger_of_the_gods/concerns/message.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#original_messageObject

Returns the value of attribute original_message.



16
17
18
# File 'lib/hermes_messenger_of_the_gods/concerns/message.rb', line 16

def original_message
  @original_message
end

#source_endpointObject

Returns the value of attribute source_endpoint.



16
17
18
# File 'lib/hermes_messenger_of_the_gods/concerns/message.rb', line 16

def source_endpoint
  @source_endpoint
end

Instance Method Details

#_build_for_transmissionObject



50
51
52
# File 'lib/hermes_messenger_of_the_gods/concerns/message.rb', line 50

def _build_for_transmission
  to_message
end

#attributesObject



58
59
60
61
62
# File 'lib/hermes_messenger_of_the_gods/concerns/message.rb', line 58

def attributes
  (self.class._defined_attributes || []).each.with_object({}) do |attr, hsh|
    hsh[attr] = send(attr)
  end
end

#dispatchObject



22
23
24
25
26
# File 'lib/hermes_messenger_of_the_gods/concerns/message.rb', line 22

def dispatch
  dispatch!
rescue StandardError
  false
end

#dispatch!(endpoint_args: {}) ⇒ Object



35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/hermes_messenger_of_the_gods/concerns/message.rb', line 35

def dispatch!(endpoint_args: {})
  validate!

  begin
    endpoint.dispatch!(self, endpoint_args) unless HermesMessengerOfTheGods.config.stub_dispatch
  rescue StandardError => e
    say_error(e)
    raise HermesMessengerOfTheGods::MessageDispatchFailed, e.message
  ensure
    endpoint.teardown
  end

  true
end

#inspectObject



64
65
66
# File 'lib/hermes_messenger_of_the_gods/concerns/message.rb', line 64

def inspect
  "<#{self.class}: #{attributes}>"
end

#retry_at(future_time_or_seconds_in_future) ⇒ Object



28
29
30
31
32
33
# File 'lib/hermes_messenger_of_the_gods/concerns/message.rb', line 28

def retry_at(future_time_or_seconds_in_future)
  raise 'unable to set visiblity' if source_endpoint.nil? || original_message.nil?
  raise "endpoint type doesn't support setting execution time" unless source_endpoint.respond_to?(:set_reexecution_time)

  source_endpoint.set_reexecution_time(original_message, future_time_or_seconds_in_future)
end

#to_messageObject



54
55
56
# File 'lib/hermes_messenger_of_the_gods/concerns/message.rb', line 54

def to_message
  attributes
end

#validate!Object



18
19
20
# File 'lib/hermes_messenger_of_the_gods/concerns/message.rb', line 18

def validate!
  raise HermesMessengerOfTheGods::ValidationError.new(self) unless valid?
end