lib/flydata/helper/action/check_remote_actions.rb in flydata-0.5.10 vs lib/flydata/helper/action/check_remote_actions.rb in flydata-0.5.11

- old
+ new

@@ -4,20 +4,38 @@ module Flydata module Helper module Action class CheckRemoteActions < BaseAction + include FlydataCore::Logger + + MAX_ERROR_RETRY = 20 + def initialize(config) super @api_client = ApiClient.instance + @retry_count = 0 end def execute(opts = {}) action_position = ActionPosition.new(config) # Get actions from flydata web server last_id = action_position.load - actions = @api_client.agent.actions(last_id) + actions = nil + begin + actions = @api_client.agent.actions(last_id) + @retry_count = 0 + rescue => e + if @retry_count >= MAX_ERROR_RETRY + @retry_count = 0 + raise + else + @retry_count += 1 + log_warn "Failed to get actions with error '#{e.to_s}'. Wait for the next turn." + actions = {'actions' => []} + end + end actions['actions'].each do |action| action_name = action['name'] action_id = action['id'].to_i action_info = { id: action_id, config: action['config'] }