Class: Marathon::Task

Inherits:
Base
  • Object
show all
Defined in:
lib/marathon/task.rb

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

#info

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Base

#to_json

Methods included from Error

error_class, error_message, from_response

Constructor Details

#initialize(hash) ⇒ Task

Create a new task object. hash: Hash including all attributes



9
10
11
# File 'lib/marathon/task.rb', line 9

def initialize(hash)
  super(hash, ACCESSORS)
end

Class Method Details

.delete(ids, scale = false) ⇒ Object Also known as: remove, kill

Kill the given list of tasks and scale apps if requested. ids: Id or list of ids with target tasks. scale: Scale the app down (i.e. decrement its instances setting by the number of tasks killed)

after killing the specified tasks.


57
58
59
# File 'lib/marathon/task.rb', line 57

def delete(ids, scale = false)
  Marathon.singleton.tasks.delete(ids,scale)
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.


68
69
70
# File 'lib/marathon/task.rb', line 68

def delete_all(appId, host = nil, scale = false)
  Marathon.singleton.tasks.delete_all(appId,host,scale)
end

.get(appId) ⇒ Object

List all running tasks for application appId. appId: Application’s id



49
50
51
# File 'lib/marathon/task.rb', line 49

def get(appId)
  Marathon.singleton.tasks.get(appId)
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.


43
44
45
# File 'lib/marathon/task.rb', line 43

def list(status = nil)
  Marathon.singleton.tasks.list(status)
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
# File 'lib/marathon/task.rb', line 16

def delete!(scale = false)
  new_task = self.class.delete(id, scale)
end

#to_pretty_sObject

Returns a string for listing the task.



26
27
28
29
30
31
32
33
34
35
36
# File 'lib/marathon/task.rb', line 26

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_sObject



21
22
23
# File 'lib/marathon/task.rb', line 21

def to_s
  "Marathon::Task { :id => #{self.id} :appId => #{appId} :host => #{host} }"
end