Class: Seam::ActionAttempt

Inherits:
BaseResource show all
Defined in:
lib/seam/resources/action_attempt.rb

Instance Attribute Summary collapse

Attributes inherited from BaseResource

#client, #data

Instance Method Summary collapse

Methods inherited from BaseResource

date_accessor, #initialize, #inspect, load_from_response, #update_from_response

Constructor Details

This class inherits a constructor from Seam::BaseResource

Instance Attribute Details

#action_attempt_idObject

Returns the value of attribute action_attempt_id.



5
6
7
# File 'lib/seam/resources/action_attempt.rb', line 5

def action_attempt_id
  @action_attempt_id
end

#action_typeObject

Returns the value of attribute action_type.



5
6
7
# File 'lib/seam/resources/action_attempt.rb', line 5

def action_type
  @action_type
end

#errorObject

Returns the value of attribute error.



5
6
7
# File 'lib/seam/resources/action_attempt.rb', line 5

def error
  @error
end

#resultObject

Returns the value of attribute result.



5
6
7
# File 'lib/seam/resources/action_attempt.rb', line 5

def result
  @result
end

#statusObject

Returns the value of attribute status.



5
6
7
# File 'lib/seam/resources/action_attempt.rb', line 5

def status
  @status
end

Instance Method Details

#decide_and_wait(wait_for_action_attempt) ⇒ Object



7
8
9
10
11
12
13
14
15
# File 'lib/seam/resources/action_attempt.rb', line 7

def decide_and_wait(wait_for_action_attempt)
  wait_decision = wait_for_action_attempt.nil? ? @client.wait_for_action_attempt : wait_for_action_attempt

  if wait_decision == true
    wait_until_finished
  elsif wait_decision.is_a?(Hash)
    wait_until_finished(timeout: wait_decision[:timeout], polling_interval: wait_decision[:polling_interval])
  end
end

#update!Object



34
35
36
37
38
39
40
41
42
43
44
# File 'lib/seam/resources/action_attempt.rb', line 34

def update!
  response = @client.request_seam(
    :post,
    "/action_attempts/get",
    body: {
      action_attempt_id: action_attempt_id
    }
  )

  update_from_response(response["action_attempt"])
end

#wait_until_finished(timeout: 5.0, polling_interval: 0.5) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/seam/resources/action_attempt.rb', line 17

def wait_until_finished(timeout: 5.0, polling_interval: 0.5)
  time_waiting = 0.0

  while @status == "pending"
    sleep(polling_interval)
    time_waiting += polling_interval

    raise "Timed out waiting for action attempt to be finished" if time_waiting > timeout

    update!

    raise "Action Attempt failed: #{error["message"]}" if @status == "failed"
  end

  self
end