Class: Marathon::Task
Overview
This class represents a Marathon Task. See mesosphere.github.io/marathon/docs/rest-api.html#get-/v2/tasks for full list of API’s methods.
Constant Summary collapse
- ACCESSORS =
%w[ id appId host ports servicePorts version stagedAt startedAt ]
Instance Attribute Summary
Attributes inherited from Base
Class Method Summary collapse
-
.delete(appId, id, scale = false) ⇒ Object
(also: remove, kill)
Kill the task that belongs to the application appId.
-
.delete_all(appId, host = nil, scale = false) ⇒ Object
(also: remove_all, kill_all)
Kill tasks that belong to the application appId.
-
.get(appId) ⇒ Object
List all running tasks for application appId.
-
.list(status = nil) ⇒ Object
List tasks of all applications.
Instance Method Summary collapse
-
#delete!(scale = false) ⇒ Object
(also: #kill!)
Kill the task that belongs to an application.
-
#initialize(hash) ⇒ Task
constructor
Create a new task object.
-
#to_pretty_s ⇒ Object
Returns a string for listing the task.
- #to_s ⇒ Object
Methods inherited from Base
Methods included from Error
error_class, error_message, from_response
Constructor Details
Class Method Details
.delete(appId, id, scale = false) ⇒ Object Also known as: remove, kill
Kill the task that belongs to the application appId. appId: Application’s id id: Id of target task. scale: Scale the app down (i.e. decrement its instances setting by the number of tasks killed)
after killing the specified tasks.
63 64 65 66 67 68 |
# File 'lib/marathon/task.rb', line 63 def delete(appId, id, scale = false) query = {} query[:scale] = true if scale json = Marathon.connection.delete("/v2/apps/#{appId}/tasks/#{id}", query) new(json) end |
.delete_all(appId, host = nil, scale = false) ⇒ Object Also known as: remove_all, kill_all
Kill tasks that belong to the application appId. appId: Application’s id host: Kill only those tasks running on host host. scale: Scale the app down (i.e. decrement its instances setting by the number of tasks killed)
after killing the specified tasks.
77 78 79 80 81 82 83 |
# File 'lib/marathon/task.rb', line 77 def delete_all(appId, host = nil, scale = false) query = {} query[:host] = host if host query[:scale] = true if scale json = Marathon.connection.delete("/v2/apps/#{appId}/tasks", query)['tasks'] json.map { |j| new(j) } end |
.get(appId) ⇒ Object
List all running tasks for application appId. appId: Application’s id
53 54 55 56 |
# File 'lib/marathon/task.rb', line 53 def get(appId) json = Marathon.connection.get("/v2/apps/#{appId}/tasks")['tasks'] json.map { |j| new(j) } end |
.list(status = nil) ⇒ Object
List tasks of all applications. status: Return only those tasks whose status matches this parameter.
If not specified, all tasks are returned. Possible values: running, staging.
44 45 46 47 48 49 |
# File 'lib/marathon/task.rb', line 44 def list(status = nil) query = {} Marathon::Util.add_choice(query, :status, status, %w[running staging]) json = Marathon.connection.get('/v2/tasks', query)['tasks'] json.map { |j| new(j) } end |
Instance Method Details
#delete!(scale = false) ⇒ Object Also known as: kill!
Kill the task that belongs to an application. scale: Scale the app down (i.e. decrement its instances setting by the number of tasks killed)
after killing the specified tasks.
16 17 18 19 |
# File 'lib/marathon/task.rb', line 16 def delete!(scale = false) new_task = self.class.delete(appId, id, scale) @info = new_task.info end |
#to_pretty_s ⇒ Object
Returns a string for listing the task.
27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/marathon/task.rb', line 27 def to_pretty_s %Q[ Task ID: #{id} App ID: #{appId} Host: #{host} Ports: #{(ports || []).join(',')} Staged at: #{stagedAt} Started at: #{startedAt} Version: #{version} ].strip end |
#to_s ⇒ Object
22 23 24 |
# File 'lib/marathon/task.rb', line 22 def to_s "Marathon::Task { :id => #{self.id} :appId => #{appId} :host => #{host} }" end |