Class: Datarobot::AiApi::Task
- Inherits:
-
Object
- Object
- Datarobot::AiApi::Task
- Includes:
- Refreshable
- Defined in:
- lib/datarobot/ai_api/task.rb
Instance Attribute Summary collapse
-
#code ⇒ Object
readonly
Returns the value of attribute code.
-
#created_at ⇒ Object
readonly
Returns the value of attribute created_at.
-
#description ⇒ Object
readonly
Returns the value of attribute description.
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#links ⇒ Object
readonly
Returns the value of attribute links.
-
#message ⇒ Object
readonly
Returns the value of attribute message.
-
#status ⇒ Object
readonly
Returns the value of attribute status.
-
#status_id ⇒ Object
readonly
Returns the value of attribute status_id.
-
#status_type ⇒ Object
readonly
Returns the value of attribute status_type.
Class Method Summary collapse
-
.find(id, &block) ⇒ Datarobot::AiApi::Task
Finds a task by id.
-
.stop(id) ⇒ Datarobot::AiApi::Task
Stops a task by id.
Instance Method Summary collapse
-
#initialize(options = {}) ⇒ Task
constructor
Given a parsed response body from the API, will create a new leanring sessoin object.
-
#set_from_options(options = {}) ⇒ void
Takes a response body from the API.
-
#wait_until_complete ⇒ Datarobot::AiApi::*
Waits for a task to complete and returns the resulting object.
Methods included from Refreshable
Constructor Details
#initialize(options = {}) ⇒ Task
Given a parsed response body from the API, will create a new leanring sessoin object
10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/datarobot/ai_api/task.rb', line 10 def initialize( = {}) # Suppresses warnings about uninitialized variables @code = nil @status = nil @status_type = nil @status_id = nil @id = nil @created_at = nil @description = nil = nil @links = nil () end |
Instance Attribute Details
#code ⇒ Object (readonly)
Returns the value of attribute code.
6 7 8 |
# File 'lib/datarobot/ai_api/task.rb', line 6 def code @code end |
#created_at ⇒ Object (readonly)
Returns the value of attribute created_at.
6 7 8 |
# File 'lib/datarobot/ai_api/task.rb', line 6 def created_at @created_at end |
#description ⇒ Object (readonly)
Returns the value of attribute description.
6 7 8 |
# File 'lib/datarobot/ai_api/task.rb', line 6 def description @description end |
#id ⇒ Object (readonly)
Returns the value of attribute id.
6 7 8 |
# File 'lib/datarobot/ai_api/task.rb', line 6 def id @id end |
#links ⇒ Object (readonly)
Returns the value of attribute links.
6 7 8 |
# File 'lib/datarobot/ai_api/task.rb', line 6 def links @links end |
#message ⇒ Object (readonly)
Returns the value of attribute message.
6 7 8 |
# File 'lib/datarobot/ai_api/task.rb', line 6 def end |
#status ⇒ Object (readonly)
Returns the value of attribute status.
6 7 8 |
# File 'lib/datarobot/ai_api/task.rb', line 6 def status @status end |
#status_id ⇒ Object (readonly)
Returns the value of attribute status_id.
6 7 8 |
# File 'lib/datarobot/ai_api/task.rb', line 6 def status_id @status_id end |
#status_type ⇒ Object (readonly)
Returns the value of attribute status_type.
6 7 8 |
# File 'lib/datarobot/ai_api/task.rb', line 6 def status_type @status_type end |
Class Method Details
.find(id, &block) ⇒ Datarobot::AiApi::Task
Finds a task by id
49 50 51 52 53 54 55 56 57 58 |
# 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 |
.stop(id) ⇒ Datarobot::AiApi::Task
Stops a task by id
64 65 66 |
# File 'lib/datarobot/ai_api/task.rb', line 64 def self.stop(id) Datarobot::AiApi.request_endpoint("/aiapi/status/#{id}", method: "delete") end |
Instance Method Details
#set_from_options(options = {}) ⇒ void
This method returns an undefined value.
Takes a response body from the API. Will set all task attributes from the response body
30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/datarobot/ai_api/task.rb', line 30 def ( = {}) # one-liner replacement for `stringify_keys` = .collect{|k,v| [k.to_s, v]}.to_h @code = .dig("code") || @code @status = .dig("status") || @status @status_type = .dig("statusType") || @status_type @status_id = .dig("statusId") || @status_id @id = .dig("statusId") || @id @created_at = .dig("created") || @created_at @description = .dig("description") || @description = .dig("message") || @links = .dig("links") || @links end |
#wait_until_complete ⇒ Datarobot::AiApi::*
Waits for a task to complete and returns the resulting object.
71 72 73 74 75 76 77 78 79 80 81 82 83 |
# 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 |