Skip to content

Commit

Permalink
Merge pull request #46 from tinaafitz/expose_max_retries
Browse files Browse the repository at this point in the history
Add ae_state_max_retries to root object.
(cherry picked from commit 03e06cd4cf1e99fb63c6cca467e6a08c2dee7dd0)

https://bugzilla.redhat.com/show_bug.cgi?id=1479407
  • Loading branch information
gmcculloug authored and simaishi committed Sep 19, 2017
1 parent d35213f commit 5d113ef
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,16 @@ def state_runnable?(f)
true
end

def initialize_state_maxima_metadata
def initialize_state_maxima_metadata(field)
@workspace.root['ae_state_started'] = Time.zone.now.utc.to_s if @workspace.root['ae_state_started'].blank?
@workspace.root['ae_state_retries'] = 0 if @workspace.root['ae_state_retries'].blank?
@workspace.root['ae_state_max_retries'] = field['max_retries'].to_i if @workspace.root['ae_state_max_retries'].to_i.zero?
end

def reset_state_maxima_metadata
@workspace.root['ae_state_started'] = ''
@workspace.root['ae_state_retries'] = 0
@workspace.root['ae_state_max_retries'] = 0
end

def increment_state_retries
Expand Down Expand Up @@ -67,7 +69,7 @@ def process_state(f, message, args)
return unless state_runnable?(f)

# Ensure the metadata to deal with retries and timeouts is initialized
initialize_state_maxima_metadata
initialize_state_maxima_metadata(f)

# Process on_entry method
process_state_step_with_error_handling(f, 'on_entry') { process_state_method(f, 'on_entry') }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,9 +91,9 @@ def create_state_class(attrs = {})
all_steps = {'on_entry' => "common_state_method",
'on_exit' => "common_state_method",
'on_error' => "common_state_method"}
ae_fields = {'state1' => {:aetype => 'state', :datatype => 'string', :priority => 1},
'state2' => {:aetype => 'state', :datatype => 'string', :priority => 2},
'state3' => {:aetype => 'state', :datatype => 'string', :priority => 3}}
ae_fields = {'state1' => {:aetype => 'state', :datatype => 'string', :priority => 1, :max_retries => 100},
'state2' => {:aetype => 'state', :datatype => 'string', :priority => 2, :max_retries => 100},
'state3' => {:aetype => 'state', :datatype => 'string', :priority => 3, :max_retries => 100}}
state1_value = "/#{@domain}/#{@namespace}/#{@method_class}/#{@instance1}"
state2_value = "/#{@domain}/#{@namespace}/#{@method_class}/#{@instance2}"
state3_value = "/#{@domain}/#{@namespace}/#{@method_class}/#{@instance3}"
Expand Down Expand Up @@ -297,6 +297,7 @@ def update_value(instance, field, attribute, value)
expect(ws.root.attributes['step_on_exit']).to match_array(%w(state1 state2))
expect(ws.root.attributes['step_on_error']).to be_nil
expect(ws.root.attributes['ae_state_retries']).to eq(1)
expect(ws.root.attributes['ae_state_max_retries']).to eq(100)
end

it "allow for retry to be set on on_exit method" do
Expand All @@ -308,6 +309,7 @@ def update_value(instance, field, attribute, value)
expect(ws.root.attributes['step_on_exit']).to match_array(%w(state1 state2))
expect(ws.root.attributes['step_on_error']).to be_nil
expect(ws.root.attributes['ae_state_retries']).to eq(1)
expect(ws.root.attributes['ae_state_max_retries']).to eq(100)
end

it "non existent on_error method" do
Expand Down

0 comments on commit 5d113ef

Please sign in to comment.