Class: Circuitry::Publisher
- Inherits:
-
Object
- Object
- Circuitry::Publisher
- 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
-
#timeout ⇒ Object
readonly
Returns the value of attribute timeout.
Attributes included from Concerns::Async
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(options = {}) ⇒ Publisher
constructor
A new instance of Publisher.
- #publish(topic_name, object) ⇒ Object
Methods included from Services::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( = {}) = DEFAULT_OPTIONS.merge() self.async = [:async] self.timeout = [:timeout] end |
Instance Attribute Details
#timeout ⇒ Object
Returns the value of attribute timeout.
19 20 21 |
# File 'lib/circuitry/publisher.rb', line 19 def timeout @timeout end |
Class Method Details
Instance Method Details
#publish(topic_name, object) ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/circuitry/publisher.rb', line 28 def publish(topic_name, object) raise ArgumentError.new('topic_name cannot be nil') if topic_name.nil? raise ArgumentError.new('object cannot be nil') if object.nil? raise PublishError.new('AWS configuration is not set') unless can_publish? process = -> do Timeout.timeout(timeout) do topic = TopicCreator.find_or_create(topic_name) sns.publish(topic_arn: topic.arn, message: object.to_json) end end if async? process_asynchronously(&process) else process.call end end |