Module: Seam::Helpers::ActionAttempt
- Defined in:
- lib/seam/helpers/action_attempt.rb
Class Method Summary collapse
- .decide_and_wait(action_attempt, client, wait_for_action_attempt) ⇒ Object
- .update_action_attempt(action_attempt, client) ⇒ Object
- .wait_until_finished(action_attempt, client, timeout: nil, polling_interval: nil) ⇒ Object
Class Method Details
.decide_and_wait(action_attempt, client, wait_for_action_attempt) ⇒ Object
8 9 10 11 12 13 14 15 16 17 |
# File 'lib/seam/helpers/action_attempt.rb', line 8 def self.decide_and_wait(action_attempt, client, wait_for_action_attempt) if wait_for_action_attempt == true return wait_until_finished(action_attempt, client) elsif wait_for_action_attempt.is_a?(Hash) return wait_until_finished(action_attempt, client, timeout: wait_for_action_attempt[:timeout], polling_interval: wait_for_action_attempt[:polling_interval]) end action_attempt end |
.update_action_attempt(action_attempt, client) ⇒ Object
39 40 41 42 43 44 |
# File 'lib/seam/helpers/action_attempt.rb', line 39 def self.update_action_attempt(action_attempt, client) response = client.get("/action_attempts/get", {action_attempt_id: action_attempt.action_attempt_id}) action_attempt.update_from_response(response.body["action_attempt"]) action_attempt end |
.wait_until_finished(action_attempt, client, timeout: nil, polling_interval: nil) ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/seam/helpers/action_attempt.rb', line 19 def self.wait_until_finished(action_attempt, client, timeout: nil, polling_interval: nil) timeout = timeout.nil? ? 5.0 : timeout polling_interval = polling_interval.nil? ? 0.5 : polling_interval time_waiting = 0.0 while action_attempt.status == "pending" sleep(polling_interval) time_waiting += polling_interval raise Seam::ActionAttemptTimeoutError.new(action_attempt, timeout) if time_waiting > timeout action_attempt = update_action_attempt(action_attempt, client) end raise Seam::ActionAttemptFailedError.new(action_attempt) if action_attempt.status == "error" action_attempt end |