Class: Datarobot::AiApi::Task

Inherits:
Object
  • Object
show all
Includes:
Refreshable
Defined in:
lib/datarobot/ai_api/task.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Refreshable

#refresh, #refresh!

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(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

Instance Attribute Details

#codeObject (readonly)

Returns the value of attribute code.



6
7
8
# File 'lib/datarobot/ai_api/task.rb', line 6

def code
  @code
end

#created_atObject (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

#descriptionObject (readonly)

Returns the value of attribute description.



6
7
8
# File 'lib/datarobot/ai_api/task.rb', line 6

def description
  @description
end

#idObject (readonly)

Returns the value of attribute id.



6
7
8
# File 'lib/datarobot/ai_api/task.rb', line 6

def id
  @id
end

Returns the value of attribute links.



6
7
8
# File 'lib/datarobot/ai_api/task.rb', line 6

def links
  @links
end

#messageObject (readonly)

Returns the value of attribute message.



6
7
8
# File 'lib/datarobot/ai_api/task.rb', line 6

def message
  @message
end

#statusObject (readonly)

Returns the value of attribute status.



6
7
8
# File 'lib/datarobot/ai_api/task.rb', line 6

def status
  @status
end

#status_idObject (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_typeObject (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

Parameters:

  • id (String)

    The id of the task to find

Returns:

Raises:



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

Parameters:

  • id (String)

    The id of the task to stop

Returns:



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

Parameters:

  • options (Hash) (defaults to: {})

    A parsed 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 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_completeDatarobot::AiApi::*

Waits for a task to complete and returns the resulting object.

Returns:



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