Class: Chimp::Task

Inherits:
Object
  • Object
show all
Defined in:
lib/right_chimp/resources/task.rb

Overview

This class allows to check on the status of any of the tasks created.

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#taskerObject

Returns the value of attribute tasker.



10
11
12
# File 'lib/right_chimp/resources/task.rb', line 10

def tasker
  @tasker
end

Instance Method Details

#detailsObject



48
49
50
# File 'lib/right_chimp/resources/task.rb', line 48

def details
  tasker.show(view: 'extended').detail
end

#friendly_urlObject



41
42
43
44
45
46
# File 'lib/right_chimp/resources/task.rb', line 41

def friendly_url
  friendly_url = Connection.audit_url + '/audit_entries/'
  friendly_url += href.split(/\//).last
  friendly_url = friendly_url.gsub('ae-', '')
  friendly_url
end

#hrefObject



37
38
39
# File 'lib/right_chimp/resources/task.rb', line 37

def href
  tasker.href
end

#stateObject



33
34
35
# File 'lib/right_chimp/resources/task.rb', line 33

def state
  tasker.show.summary
end

#wait_for_completed(timeout = 900) ⇒ Object



29
30
31
# File 'lib/right_chimp/resources/task.rb', line 29

def wait_for_completed(timeout = 900)
  wait_for_state('completed', timeout)
end

#wait_for_state(desired_state, timeout = 900) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/right_chimp/resources/task.rb', line 12

def wait_for_state(desired_state, timeout = 900)
  while timeout > 0
    # Make compatible with RL10.
    state = tasker.show.summary.downcase
    return true if state.match(desired_state)
    friendly_url = Connection.audit_url + '/audit_entries/'
    friendly_url += href.split(/\//).last
    friendly_url = friendly_url.gsub('ae-', '')
    if state.match('failed') || state.match('aborted')
      raise "FATAL error, #{tasker.show.summary}\n\n Audit: #{friendly_url}\n "
    end
    sleep 30
    timeout -= 30
  end
  raise "FATAL: Timeout waiting for Executable to complete.  State was #{self.state}" if timeout <= 0
end