Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion codegen/layouts/client.hbs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# frozen_string_literal: true
{{#if importActionAttempt}}

require "seam/helpers/action_attempt"
require "seam/action_attempt_resolver"
{{/if}}

module Seam
Expand Down
2 changes: 1 addition & 1 deletion codegen/layouts/partials/client-method.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@

wait_for_action_attempt = wait_for_action_attempt.nil? ? @defaults.wait_for_action_attempt : wait_for_action_attempt

Helpers::ActionAttempt.decide_and_wait(Seam::Resources::ActionAttempt.load_from_response(res.body["{{returnPath}}"]), @client, wait_for_action_attempt)
Seam::ActionAttemptResolver.resolve(Seam::Resources::ActionAttempt.load_from_response(res.body["{{returnPath}}"]), @client, wait_for_action_attempt)
{{/if}}
{{#if isNil}}

Expand Down
54 changes: 54 additions & 0 deletions lib/seam/action_attempt_resolver.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
# frozen_string_literal: true

require_relative "wait_for_action_attempt"

module Seam
class ActionAttemptResolver
def self.resolve(action_attempt, client, wait_for_action_attempt)
return wait_until_resolved(action_attempt, client) if wait_for_action_attempt == true

options = wait_options(wait_for_action_attempt)
return action_attempt if options.nil?

wait_until_resolved(action_attempt, client, timeout: options[:timeout],
polling_interval: options[:polling_interval])
end

# 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.
def self.wait_options(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

def self.wait_until_resolved(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

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
end
end
56 changes: 0 additions & 56 deletions lib/seam/helpers/action_attempt.rb

This file was deleted.

8 changes: 4 additions & 4 deletions lib/seam/routes/access_methods.rb

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions lib/seam/routes/acs_encoders.rb

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions lib/seam/routes/acs_entrances.rb

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions lib/seam/routes/action_attempts.rb

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions lib/seam/routes/locks.rb

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions lib/seam/routes/locks_simulate.rb

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 9 additions & 9 deletions lib/seam/routes/thermostats.rb

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Loading