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_options(wait_for_action_attempt) ⇒ Object
The client wraps its defaults in a DeepHashAccessor, so the hash form of this option reaches here as an accessor when it comes from the client and as a plain Hash when it comes from the method call.
- .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 |
# File 'lib/seam/helpers/action_attempt.rb', line 8 def self.decide_and_wait(action_attempt, client, wait_for_action_attempt) return wait_until_finished(action_attempt, client) if wait_for_action_attempt == true = (wait_for_action_attempt) return action_attempt if .nil? wait_until_finished(action_attempt, client, timeout: [:timeout], polling_interval: [:polling_interval]) end |
.update_action_attempt(action_attempt, client) ⇒ Object
48 49 50 51 52 53 |
# File 'lib/seam/helpers/action_attempt.rb', line 48 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_options(wait_for_action_attempt) ⇒ Object
The client wraps its defaults in a DeepHashAccessor, so the hash form of this option reaches here as an accessor when it comes from the client and as a plain Hash when it comes from the method call.
21 22 23 24 25 26 |
# File 'lib/seam/helpers/action_attempt.rb', line 21 def self.(wait_for_action_attempt) case wait_for_action_attempt when Hash then wait_for_action_attempt when Seam::DeepHashAccessor then wait_for_action_attempt.to_h end end |
.wait_until_finished(action_attempt, client, timeout: nil, polling_interval: nil) ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/seam/helpers/action_attempt.rb', line 28 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 |