Class: QuickQueue::Client
- Inherits:
-
Object
- Object
- QuickQueue::Client
- Defined in:
- lib/quick_queue/client.rb
Direct Known Subclasses
Instance Method Summary collapse
- #fetch ⇒ Object (also: #pop)
- #handle(item) ⇒ Object
-
#initialize(options = {}) ⇒ Client
constructor
A new instance of Client.
- #loop ⇒ Object
- #push(item) ⇒ Object
- #server_status ⇒ Object (also: #status)
Constructor Details
#initialize(options = {}) ⇒ Client
Returns a new instance of Client.
5 6 7 8 9 10 11 12 |
# File 'lib/quick_queue/client.rb', line 5 def initialize( = {}) port = ([:port] || 7654) host = ([:host] || 'localhost') @worker = File.read([:file]) if [:file] DRb.start_service() @server = DRbObject.new(nil, "druby://#{host}:#{port}") @current_item = nil end |
Instance Method Details
#fetch ⇒ Object Also known as: pop
14 15 16 |
# File 'lib/quick_queue/client.rb', line 14 def fetch @server.pop end |
#handle(item) ⇒ Object
46 47 48 |
# File 'lib/quick_queue/client.rb', line 46 def handle(item) puts item end |
#loop ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/quick_queue/client.rb', line 28 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}: #{$!.} at #{$!.backtrace.first}") if @logger @server.push(@current_item) @current_item = nil end end end end |
#push(item) ⇒ Object
19 20 21 |
# File 'lib/quick_queue/client.rb', line 19 def push(item) @server.push(item) end |
#server_status ⇒ Object Also known as: status
23 24 25 |
# File 'lib/quick_queue/client.rb', line 23 def server_status @server.status end |