class Datarobot::AiApi::Task
Attributes
code[R]
created_at[R]
description[R]
id[R]
links[R]
message[R]
status[R]
status_id[R]
status_type[R]
Public Class Methods
find(id) { |data| ... }
click to toggle source
Finds a task by id
@param [String] id The id of the task to find @return [Datarobot::AiApi::Task]
# File lib/datarobot/ai_api/task.rb, line 49 def self.find(id, &block) raise Datarobot::AiApi::NotFoundError, "Cannot find Task with id: nil" if id.nil? Datarobot::AiApi.request_endpoint("/aiapi/status/#{id}") do |data| if block_given? yield data else self.new(data) end end end
new(options = {})
click to toggle source
Given a parsed response body from the API, will create a new leanring sessoin object
# File lib/datarobot/ai_api/task.rb, line 10 def initialize(options = {}) # Suppresses warnings about uninitialized variables @code = nil @status = nil @status_type = nil @status_id = nil @id = nil @created_at = nil @description = nil @message = nil @links = nil set_from_options(options) end
stop(id)
click to toggle source
Stops a task by id
@param [String] id The id of the task to stop @return [Datarobot::AiApi::Task]
# File lib/datarobot/ai_api/task.rb, line 64 def self.stop(id) Datarobot::AiApi.request_endpoint("/aiapi/status/#{id}", method: "delete") end
Public Instance Methods
set_from_options(options = {})
click to toggle source
Takes a response body from the API. Will set all task attributes from the response body
@param [Hash] options A parsed response body @return [void]
# File lib/datarobot/ai_api/task.rb, line 30 def set_from_options(options = {}) # one-liner replacement for `stringify_keys` options = options.collect{|k,v| [k.to_s, v]}.to_h @code = options.dig("code") || @code @status = options.dig("status") || @status @status_type = options.dig("statusType") || @status_type @status_id = options.dig("statusId") || @status_id @id = options.dig("statusId") || @id @created_at = options.dig("created") || @created_at @description = options.dig("description") || @description @message = options.dig("message") || @message @links = options.dig("links") || @links end
wait_until_complete()
click to toggle source
Waits for a task to complete and returns the resulting object.
@return [Datarobot::AiApi::*]
# File lib/datarobot/ai_api/task.rb, line 71 def wait_until_complete refreshed = self until refreshed.status == 'COMPLETED' sleep 1 unless ENV['FAST_TEST_RESPONSE'] == 'true' refreshed = Datarobot::AiApi::Task.find(@id) end result = refreshed.links["result"] Datarobot::AiApi.get(result) do |data| klass = Datarobot::AiApi.determine_object(result) klass.new(data) end end