Class: Eventboss::UnitOfWork
- Inherits:
-
Object
- Object
- Eventboss::UnitOfWork
- Includes:
- Logging, SafeThread
- Defined in:
- lib/eventboss/unit_of_work.rb
Overview
UnitOfWork handles calls a listener for each message and deletes on success
Instance Attribute Summary collapse
-
#listener ⇒ Object
Returns the value of attribute listener.
-
#message ⇒ Object
Returns the value of attribute message.
-
#queue ⇒ Object
Returns the value of attribute queue.
Instance Method Summary collapse
- #cleanup(client) ⇒ Object
-
#initialize(queue, listener, message) ⇒ UnitOfWork
constructor
A new instance of UnitOfWork.
- #run(client) ⇒ Object
Methods included from SafeThread
#handle_exception, #safe_thread
Methods included from Logging
Constructor Details
#initialize(queue, listener, message) ⇒ UnitOfWork
Returns a new instance of UnitOfWork.
9 10 11 12 13 |
# File 'lib/eventboss/unit_of_work.rb', line 9 def initialize(queue, listener, ) @queue = queue @listener = listener @message = end |
Instance Attribute Details
#listener ⇒ Object
Returns the value of attribute listener.
7 8 9 |
# File 'lib/eventboss/unit_of_work.rb', line 7 def listener @listener end |
#message ⇒ Object
Returns the value of attribute message.
7 8 9 |
# File 'lib/eventboss/unit_of_work.rb', line 7 def @message end |
#queue ⇒ Object
Returns the value of attribute queue.
7 8 9 |
# File 'lib/eventboss/unit_of_work.rb', line 7 def queue @queue end |
Instance Method Details
#cleanup(client) ⇒ Object
26 27 28 29 30 31 |
# File 'lib/eventboss/unit_of_work.rb', line 26 def cleanup(client) client.( queue_url: @queue.url, receipt_handle: @message.receipt_handle ) logger.debug('Deleting', @message.) end |
#run(client) ⇒ Object
15 16 17 18 19 20 21 22 23 24 |
# File 'lib/eventboss/unit_of_work.rb', line 15 def run(client) logger.debug('Started', @message.) processor = @listener.new processor.receive(JSON.parse(@message.body)) logger.info('Finished', @message.) rescue StandardError => exception handle_exception(exception, processor: processor, message_id: @message.) else cleanup(client) end |