Class: Aliyun::Odps::Instance
- Inherits:
-
Struct::Base
- Object
- Struct::Base
- Aliyun::Odps::Instance
- Extended by:
- Modelable
- Defined in:
- lib/aliyun/odps/model/instance.rb
Constant Summary collapse
- NAME_PATTERN =
/^([a-z]|[A-Z]){1,}([a-z]|[A-Z]|[\d]|_)*/
Instance Attribute Summary collapse
- #comment ⇒ String
- #end_time ⇒ DateTime
- #location ⇒ String
- #name ⇒ String
- #owner ⇒ String
- #priority ⇒ Integer
- #project ⇒ Project
- #start_time ⇒ DateTime
- #status ⇒ String
- #tasks ⇒ Array
Instance Method Summary collapse
-
#get_status ⇒ String
Get status.
-
#list_tasks ⇒ List
Get tasks of instance.
-
#task_detail(task_name) ⇒ Hash
Get task detail of instance.
-
#task_progress(task_name) ⇒ Hash
Get task progress of instance.
-
#task_results ⇒ Hash<name, TaskResult>
Get task results.
-
#task_summary(task_name) ⇒ Hash
Get task summary of instance.
-
#terminate ⇒ Object
Terminate the instance.
-
#wait_for_success(interval = 0.01) ⇒ Object
Block process until instance success.
-
#wait_for_terminated(interval = 0.01) ⇒ Object
Block process until instance terminated.
Methods included from Modelable
Methods inherited from Struct::Base
#client, #initialize, property, #update_attrs
Constructor Details
This class inherits a constructor from Aliyun::Odps::Struct::Base
Instance Attribute Details
#comment ⇒ String
12 |
# File 'lib/aliyun/odps/model/instance.rb', line 12 property :comment, String |
#end_time ⇒ DateTime
17 |
# File 'lib/aliyun/odps/model/instance.rb', line 17 property :end_time, DateTime |
#location ⇒ String
18 |
# File 'lib/aliyun/odps/model/instance.rb', line 18 property :location, String |
#name ⇒ String
10 |
# File 'lib/aliyun/odps/model/instance.rb', line 10 property :name, String, required: true |
#owner ⇒ String
11 |
# File 'lib/aliyun/odps/model/instance.rb', line 11 property :owner, String |
#priority ⇒ Integer
13 |
# File 'lib/aliyun/odps/model/instance.rb', line 13 property :priority, Integer |
#project ⇒ Project
8 |
# File 'lib/aliyun/odps/model/instance.rb', line 8 property :project, Project, required: true |
#start_time ⇒ DateTime
16 |
# File 'lib/aliyun/odps/model/instance.rb', line 16 property :start_time, DateTime |
#status ⇒ String
15 |
# File 'lib/aliyun/odps/model/instance.rb', line 15 property :status, String |
#tasks ⇒ Array
14 |
# File 'lib/aliyun/odps/model/instance.rb', line 14 property :tasks, Array |
Instance Method Details
#get_status ⇒ String
Get status
105 106 107 108 109 |
# File 'lib/aliyun/odps/model/instance.rb', line 105 def get_status path = "/projects/#{project.name}/instances/#{name}" result = client.get(path).parsed_response Utils.dig_value(result, 'Instance', 'Status') end |
#list_tasks ⇒ List
Get tasks of instance
75 76 77 78 79 80 81 82 83 84 |
# File 'lib/aliyun/odps/model/instance.rb', line 75 def list_tasks path = "/projects/#{project.name}/instances/#{name}" query = { taskstatus: true } result = client.get(path, query: query).parsed_response keys = %w(Instance Tasks Task) Utils.wrap(Utils.dig_value(result, *keys)).map do |hash| InstanceTask.new(hash) end end |
#task_detail(task_name) ⇒ Hash
Get task detail of instance
27 28 29 30 31 |
# File 'lib/aliyun/odps/model/instance.rb', line 27 def task_detail(task_name) path = "/projects/#{project.name}/instances/#{name}" query = { instancedetail: true, taskname: task_name } client.get(path, query: query).parsed_response end |
#task_progress(task_name) ⇒ Hash
Get task progress of instance
40 41 42 43 44 |
# File 'lib/aliyun/odps/model/instance.rb', line 40 def task_progress(task_name) path = "/projects/#{project.name}/instances/#{name}" query = { instanceprogress: true, taskname: task_name } client.get(path, query: query).parsed_response['Progress'] end |
#task_results ⇒ Hash<name, TaskResult>
Get task results
62 63 64 65 66 67 68 |
# File 'lib/aliyun/odps/model/instance.rb', line 62 def task_results path = "/projects/#{project.name}/instances/#{name}" query = { result: true } result = client.get(path, query: query).parsed_response task_results = Utils.dig_value(result, 'Instance', 'Tasks', 'Task') Hash[Utils.wrap(task_results).map { |v| [v['Name'], Aliyun::Odps::TaskResult.new(v)] }] end |
#task_summary(task_name) ⇒ Hash
Get task summary of instance
53 54 55 56 57 |
# File 'lib/aliyun/odps/model/instance.rb', line 53 def task_summary(task_name) path = "/projects/#{project.name}/instances/#{name}" query = { instancesummary: true, taskname: task_name } client.get(path, query: query).parsed_response end |
#terminate ⇒ Object
Terminate the instance
91 92 93 94 95 96 97 98 |
# File 'lib/aliyun/odps/model/instance.rb', line 91 def terminate path = "/projects/#{project.name}/instances/#{name}" body = Utils.to_xml( 'Instance' => { 'Status' => 'Terminated' } ) !!client.put(path, body: body) end |
#wait_for_success(interval = 0.01) ⇒ Object
Block process until instance success
114 115 116 117 118 119 120 121 122 |
# File 'lib/aliyun/odps/model/instance.rb', line 114 def wait_for_success(interval = 0.01) wait_for_terminated(interval) list_tasks.each do |task| if task.status.upcase != 'SUCCESS' fail InstanceTaskNotSuccessError.new(task.name, task.status, task_results[task.name].result) end end end |
#wait_for_terminated(interval = 0.01) ⇒ Object
Block process until instance terminated
125 126 127 |
# File 'lib/aliyun/odps/model/instance.rb', line 125 def wait_for_terminated(interval = 0.01) sleep interval while get_status != 'Terminated' end |