Sha256: 39cbb39298f47d219f334944fb87d574d723f176a5a3d3476cc4b3da9f2dba8f

Contents?: true

Size: 1.75 KB

Versions: 24

Compression:

Stored size: 1.75 KB

Contents

require 'logger'

module Support
  module RescueExample

    class ComplexActionWithSkip < Dynflow::Action

      def plan(error_state)
        sequence do
          concurrence do
            plan_action(ActionWithSkip, 3, :success)
            plan_action(ActionWithSkip, 4, error_state)
          end
          plan_action(ActionWithSkip, 5, :success)
        end
      end
    end

    class ComplexActionWithoutSkip < ComplexActionWithSkip

      def rescue_strategy_for_planned_action(action)
        # enforce pause even when error on skipable action
        Dynflow::Action::Rescue::Pause
      end

    end

    class AbstractAction < Dynflow::Action

      def plan(identifier, desired_state)
        plan_self(identifier: identifier, desired_state: desired_state)
      end

      def run
        case input[:desired_state].to_sym
        when :success, :error_on_finalize
          output[:message] = 'Been here'
        when :error_on_run, :error_on_skip
          raise 'some error as you wish'
        when :pending
          raise 'we were not supposed to get here'
        else
          raise "unkown desired state #{input[:desired_state]}"
        end
      end

      def finalize
        case input[:desired_state].to_sym
        when :error_on_finalize, :error_on_skip
          raise 'some error as you wish'
        end
      end

    end

    class ActionWithSkip < AbstractAction

      def run(event = nil)
        if event === Dynflow::Action::Skip
          output[:message] = "skipped because #{self.error.message}"
          raise 'we failed on skip as well' if input[:desired_state].to_sym == :error_on_skip
        else
          super()
        end
      end

      def rescue_strategy_for_self
        Dynflow::Action::Rescue::Skip
      end

    end
  end
end

Version data entries

24 entries across 24 versions & 1 rubygems

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