class Qube::Tube
Attributes
name[R]
Public Class Methods
new(options = {})
click to toggle source
# File lib/qube/model/tube.rb, line 5 def initialize(options = {}) @config = Qube.config @client = Client.new @name = options.delete(:name) @type = options.delete(:type) @options = options.merge!(if_not_exists: true) fetch_or_create_tube end
Public Instance Methods
ack(data)
click to toggle source
PUT tubes/:name/:task_id/ask
# File lib/qube/model/tube.rb, line 26 def ack(data) task_id = data.is_a?(Hash) ? data.dig('task_id') : data response = @client.put("tubes/#{@name}/#{task_id}/ack", tube: @name, task_id: task_id) response.code == 200 end
drop()
click to toggle source
DELETE tubes/:name
# File lib/qube/model/tube.rb, line 33 def drop response = @client.delete("tubes/#{@name}") response.code == 200 end
each_task(timeout = 0) { |task| ... }
click to toggle source
# File lib/qube/model/tube.rb, line 38 def each_task(timeout = 0) loop do task = take(timeout) if task.nil? || task.empty? break else yield task ack(task) end end end
put(task, options = {})
click to toggle source
POST tubes/:name
# File lib/qube/model/tube.rb, line 15 def put(task, options = {}) response = @client.post("tubes/#{@name}", tube: @name, task: task, options: options) response.code == 200 end
take(timeout = 0)
click to toggle source
GET tubes/:name
# File lib/qube/model/tube.rb, line 21 def take(timeout = 0) @client.get("tubes/#{@name}", timeout: timeout)&.body end
Private Instance Methods
fetch_or_create_tube()
click to toggle source
# File lib/qube/model/tube.rb, line 52 def fetch_or_create_tube response = @client.post('tubes', tube: @name, type: @type, options: @options.compact) self if response.code == 200 end