Class: Circuitry::Publisher

Inherits:
Object
  • Object
show all
Includes:
Concerns::Async, Services::SNS
Defined in:
lib/circuitry/publisher.rb

Constant Summary collapse

DEFAULT_OPTIONS =
{
  async: false,
  timeout: 15
}.freeze

Instance Attribute Summary collapse

Attributes included from Concerns::Async

#async

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Services::SNS

#sns

Methods included from Concerns::Async

#async?, included, #process_asynchronously

Constructor Details

#initialize(options = {}) ⇒ Publisher

Returns a new instance of Publisher.



21
22
23
24
25
26
# File 'lib/circuitry/publisher.rb', line 21

def initialize(options = {})
  options = DEFAULT_OPTIONS.merge(options)

  self.async = options[:async]
  self.timeout = options[:timeout]
end

Instance Attribute Details

#timeoutObject

Returns the value of attribute timeout.



19
20
21
# File 'lib/circuitry/publisher.rb', line 19

def timeout
  @timeout
end

Class Method Details

.default_async_strategyObject



40
41
42
# File 'lib/circuitry/publisher.rb', line 40

def self.default_async_strategy
  Circuitry.config.publish_async_strategy
end

Instance Method Details

#publish(topic_name, object) ⇒ Object

Raises:

  • (ArgumentError)


28
29
30
31
32
33
34
35
36
37
38
# File 'lib/circuitry/publisher.rb', line 28

def publish(topic_name, object)
  raise ArgumentError, 'topic_name cannot be nil' if topic_name.nil?
  raise ArgumentError, 'object cannot be nil' if object.nil?
  raise PublishError, 'AWS configuration is not set' unless can_publish?

  if async?
    process_asynchronously(& -> { publish_internal(topic_name, object) })
  else
    publish_internal(topic_name, object)
  end
end