Class: Chimp::Task
- Inherits:
-
Object
- Object
- Chimp::Task
- 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
-
#tasker ⇒ Object
Returns the value of attribute tasker.
Instance Method Summary collapse
- #details ⇒ Object
- #friendly_url ⇒ Object
- #href ⇒ Object
-
#initialize ⇒ Task
constructor
A new instance of Task.
- #state ⇒ Object
- #wait_for_completed(timeout = 900) ⇒ Object
- #wait_for_state(desired_state, timeout = 900) ⇒ Object
Constructor Details
#initialize ⇒ Task
Returns a new instance of Task.
12 13 14 15 |
# File 'lib/right_chimp/resources/task.rb', line 12 def initialize rate = ENV['API_POLLING_RATE'] || 30 @api_polling_rate = rate.to_i end |
Instance Attribute Details
#tasker ⇒ Object
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
#details ⇒ Object
54 55 56 |
# File 'lib/right_chimp/resources/task.rb', line 54 def details tasker.show(view: 'extended').detail end |
#friendly_url ⇒ Object
47 48 49 50 51 52 |
# File 'lib/right_chimp/resources/task.rb', line 47 def friendly_url friendly_url = Connection.audit_url + '/audit_entries/' friendly_url += href.split(/\//).last friendly_url = friendly_url.gsub('ae-', '') friendly_url end |
#href ⇒ Object
43 44 45 |
# File 'lib/right_chimp/resources/task.rb', line 43 def href tasker.href end |
#state ⇒ Object
39 40 41 |
# File 'lib/right_chimp/resources/task.rb', line 39 def state tasker.show.summary end |
#wait_for_completed(timeout = 900) ⇒ Object
35 36 37 |
# File 'lib/right_chimp/resources/task.rb', line 35 def wait_for_completed(timeout = 900) wait_for_state('completed', timeout) end |
#wait_for_state(desired_state, timeout = 900) ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/right_chimp/resources/task.rb', line 17 def wait_for_state(desired_state, timeout = 900) while timeout > 0 # Make compatible with RL10. status = state.downcase return true if status.match(desired_state) friendly_url = Connection.audit_url + '/audit_entries/' friendly_url += href.split(/\//).last friendly_url = friendly_url.gsub('ae-', '') if status.match('failed') || status.match('aborted') raise "FATAL error, #{status}\n\n Audit: #{friendly_url}\n " end Log.debug "Polling again in #{@api_polling_rate}" sleep @api_polling_rate timeout -= @api_polling_rate end raise "FATAL: Timeout waiting for Executable to complete. State was #{status}" if timeout <= 0 end |