Class: QuickQueue::Client
- Inherits:
-
Object
- Object
- QuickQueue::Client
- Defined in:
- lib/quick_queue/client.rb
Instance Method Summary collapse
- #fetch ⇒ Object
- #handle(item) ⇒ Object
-
#initialize(options = {}) ⇒ Client
constructor
A new instance of Client.
- #loop ⇒ Object
- #push(item) ⇒ Object
- #server_status ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ Client
Returns a new instance of Client.
5 6 7 8 9 10 11 |
# File 'lib/quick_queue/client.rb', line 5 def initialize( = {}) port = ([:port] || 7654) host = ([:host] || 'localhost') DRb.start_service() @server = DRbObject.new(nil, "druby://#{host}:#{port}") @current_item = nil end |
Instance Method Details
#fetch ⇒ Object
13 14 15 |
# File 'lib/quick_queue/client.rb', line 13 def fetch @server.pop end |
#handle(item) ⇒ Object
43 44 45 |
# File 'lib/quick_queue/client.rb', line 43 def handle(item) puts item end |
#loop ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/quick_queue/client.rb', line 25 def loop while item = fetch begin @current_item = item handle(item) @current_item = nil rescue # if something went wrong, put it back in the queue if @current_item @logger.info("Failed to process #{@current_item}, putting it back in queue") if @logger @logger.info("Reason for failure: #{$!.class}: #{$!.message} at #{$!.backtrace.first}") if @logger @server.push(@current_item) @current_item = nil end end end end |
#push(item) ⇒ Object
17 18 19 |
# File 'lib/quick_queue/client.rb', line 17 def push(item) @server.push(item) end |
#server_status ⇒ Object
21 22 23 |
# File 'lib/quick_queue/client.rb', line 21 def server_status @server.status end |