Sha256: 2a272ccf9a5f8efdbb8be0deea4d9fff3511ab31fccdc4b63af0ca5b99990901

Contents?: true

Size: 1.74 KB

Versions: 24

Compression:

Stored size: 1.74 KB

Contents

module Dynflow
  module Action::Rescue

    Strategy = Algebrick.type do
      variants Skip = atom, Pause = atom
    end

    SuggestedStrategy = Algebrick.type do
      fields! action:   Action,
              strategy: Strategy
    end

    # What strategy should be used for rescuing from error in
    # the action or its sub actions
    #
    # @return Strategy
    #
    # When determining the strategy, the algorithm starts from the
    # entry action that by default takes the strategy from #rescue_strategy_for_self
    # and #rescue_strategy_for_planned_actions and combines them together.
    def rescue_strategy
      suggested_strategies = []

      if self.steps.compact.any? { |step| step.state == :error }
        suggested_strategies << SuggestedStrategy[self, rescue_strategy_for_self]
      end

      self.planned_actions.each do |planned_action|
        suggested_strategies << SuggestedStrategy[planned_action, rescue_strategy_for_planned_action(planned_action)]
      end

      combine_suggested_strategies(suggested_strategies)
    end

    # Override when another strategy should be used for rescuing from
    # error on the action
    def rescue_strategy_for_self
      return Pause
    end

    # Override when the action should override the rescue
    # strategy of an action it planned
    def rescue_strategy_for_planned_action(action)
      action.rescue_strategy
    end

    # Override when different appraoch should be taken for combining
    # the suggested strategies
    def combine_suggested_strategies(suggested_strategies)
      if suggested_strategies.empty? ||
            suggested_strategies.all? { |suggested_strategy| suggested_strategy.strategy == Skip }
        return Skip
      else
        return Pause
      end
    end
  end
end

Version data entries

24 entries across 24 versions & 1 rubygems

Version Path
dynflow-0.8.13 lib/dynflow/action/rescue.rb
dynflow-0.8.12 lib/dynflow/action/rescue.rb
dynflow-0.8.11 lib/dynflow/action/rescue.rb
dynflow-0.8.10 lib/dynflow/action/rescue.rb
dynflow-0.8.9 lib/dynflow/action/rescue.rb
dynflow-0.8.8 lib/dynflow/action/rescue.rb
dynflow-0.8.7 lib/dynflow/action/rescue.rb
dynflow-0.8.6 lib/dynflow/action/rescue.rb
dynflow-0.8.5 lib/dynflow/action/rescue.rb
dynflow-0.8.4 lib/dynflow/action/rescue.rb
dynflow-0.8.3 lib/dynflow/action/rescue.rb
dynflow-0.8.2 lib/dynflow/action/rescue.rb
dynflow-0.8.1 lib/dynflow/action/rescue.rb
dynflow-0.8.0 lib/dynflow/action/rescue.rb
dynflow-0.7.9 lib/dynflow/action/rescue.rb
dynflow-0.7.8 lib/dynflow/action/rescue.rb
dynflow-0.7.7 lib/dynflow/action/rescue.rb
dynflow-0.7.6 lib/dynflow/action/rescue.rb
dynflow-0.7.5 lib/dynflow/action/rescue.rb
dynflow-0.7.4 lib/dynflow/action/rescue.rb