module Crowdkit
Constants
- VERSION
Public Class Methods
configure(overrides={}, &block)
click to toggle source
# File lib/crowdkit.rb, line 31 def self.configure(overrides={}, &block) @configuration = Config.new(overrides, &block) end
last_response()
click to toggle source
# File lib/crowdkit.rb, line 23 def self.last_response @last_response end
last_response=(last_response)
click to toggle source
# File lib/crowdkit.rb, line 27 def self.last_response=(last_response) @last_response = last_response end
new(overrides={}, &block)
click to toggle source
# File lib/crowdkit.rb, line 14 def self.new(overrides={}, &block) #Use the global config if no overrides present if @configuration && overrides.empty? && !block_given? Client.new(@configuration) else Client.new(overrides, &block) end end
reset!()
click to toggle source
# File lib/crowdkit.rb, line 35 def self.reset! @last_response = nil @configuration = nil end
wait_on_status(resource, max_time_to_wait_in_seconds = 30)
click to toggle source
This takes a response from a resource that processes something in the background (i.e. a 202 response) and will ping the status API
until it timesout an error is returned, or the background process is completed.
# File lib/crowdkit.rb, line 43 def self.wait_on_status(resource, max_time_to_wait_in_seconds = 30) raise ArgumentError, "This resource did not respond with a 202 status code and has no status to wait on." unless resource.last_response.status == 202 progressbar = ProgressBar.create(total: 100) status = resource.current_status wait = 1 max_time_to_wait_in_seconds.times do |i| break if status.state == "completed" raise StatusError.new(status) if ["failed", "killed"].include?(status.state) #increase wait time to 5 seconds after 5 seconds wait = 5 if i == 5 #increase wait time to 10 seconds after 30 seconds wait = 10 if i == 30 if i % wait == 0 percents = status.percent_complete.to_i progressbar.progress = percents if percents > 0 sleep(wait) status = resource.current_status end end raise StatusError.new(status, true) unless status.state == "completed" progressbar.finish status end
Private Class Methods
method_missing(method_name, *args, &block)
click to toggle source
Not convinced we even want to support this…
Calls superclass method
# File lib/crowdkit.rb, line 74 def self.method_missing(method_name, *args, &block) return super unless new.respond_to?(method_name) new.send(method_name, *args, &block) end