Class: Qubole::Command

Inherits:
OpenStruct
  • Object
show all
Defined in:
lib/qubole/command.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.find(id) ⇒ Command

Find command by id

Parameters:

  • id (Integer)

    command id

Returns:



24
25
26
27
# File 'lib/qubole/command.rb', line 24

def self.find(id)
  command = Qubole.get("/commands/#{id}")
  new(command)
end

.page(page, opts = {}) ⇒ Array<Command>

Paginated commands history

Parameters:

  • page (Integer)

    page number

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

    addional options

  • attrs (Hash)

    a customizable set of options

Returns:

  • (Array<Command>)

    paginated commands



12
13
14
15
16
17
# File 'lib/qubole/command.rb', line 12

def self.page(page, opts = {})
  per_page = opts[:per_page] || 10
  Qubole.get('/commands', page: page, per_page: per_page)['commands'].map do |command|
    new(command)
  end
end

Instance Method Details

#cancelObject

Cancel command



87
88
89
# File 'lib/qubole/command.rb', line 87

def cancel
  Qubole.put("/commands/#{id}")
end

#jobsHash

Hadoop jobs spawned by command

Returns:

  • (Hash)

    parsed JSON response



80
81
82
# File 'lib/qubole/command.rb', line 80

def jobs
  Qubole.get("/commands/#{id}/jobs")
end

#logsString

Fetch command logs

Returns:

  • (String)

    command logs



72
73
74
# File 'lib/qubole/command.rb', line 72

def logs
  Qubole.get("/commands/#{id}/logs")
end

#parse(attrs) ⇒ Command

Update command attributes

Parameters:

  • attrs (Hash)

    command attributes

Returns:



34
35
36
37
38
# File 'lib/qubole/command.rb', line 34

def parse(attrs)
  attrs.each do |key, value|
    send("#{key}=", value)
  end
end

#refresh!Command

Refresh command attributes

Returns:



55
56
57
58
# File 'lib/qubole/command.rb', line 55

def refresh!
  command = Qubole.get("/commands/#{id}")
  parse(command)
end

#resultsHash

Fetch command results

Returns:

  • (Hash)

    parsed JSON response



64
65
66
# File 'lib/qubole/command.rb', line 64

def results
  Qubole.get("/commands/#{id}/results")
end

#submit(params = {}) ⇒ Command

Submit command to Qubole

Parameters:

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

    command payload

Returns:



45
46
47
48
49
# File 'lib/qubole/command.rb', line 45

def submit(params = {})
  parse(params)
  response = Qubole.post('/commands', self.to_h)
  parse(response)
end