Sha256: e5aa356b1ec474198ee9d428829b7c97b0a79d90e263baa0bf0041b3b8ea38b4

Contents?: true

Size: 1.55 KB

Versions: 70

Compression:

Stored size: 1.55 KB

Contents

module Dynflow

  # Methods for specifying the progress of the action
  # the +*_progress+ methods should return number in 0..1.
  # The weight is there to increase/decrease the portion of this task
  # in the context of other tasks in execution plan. Normal action has
  # weight 1.
  #
  # The +*_progress+ is run only when the action is in running/suspend state. Otherwise
  # the progress is 1 for success/skipped actions and 0 for errorneous ones.
  module Action::Progress

    class Calculate < Middleware

      def run(*args)
        with_progress_calculation(*args) do
          [action.run_progress, action.run_progress_weight]
        end
      end

      def finalize(*args)
        with_progress_calculation(*args) do
          [action.finalize_progress, action.finalize_progress_weight]
        end
      end

      protected

      def with_progress_calculation(*args)
        pass(*args)
      ensure
        begin
          action.calculated_progress = yield
        rescue => error
          # we don't want progress calculation to cause fail of the whole process
          # TODO: introduce post-execute state for handling issues with additional
          # calculations after the step is run
          action.action_logger.error('Error in progress calculation')
          action.action_logger.error(error)
        end
      end
    end

    def run_progress
      0.5
    end

    def run_progress_weight
      1
    end

    def finalize_progress
      0.5
    end

    def finalize_progress_weight
      1
    end

    attr_accessor :calculated_progress
  end
end

Version data entries

70 entries across 70 versions & 1 rubygems

Version Path
dynflow-0.8.16 lib/dynflow/action/progress.rb
dynflow-0.8.15 lib/dynflow/action/progress.rb
dynflow-0.8.14 lib/dynflow/action/progress.rb
dynflow-0.8.13 lib/dynflow/action/progress.rb
dynflow-0.8.12 lib/dynflow/action/progress.rb
dynflow-0.8.11 lib/dynflow/action/progress.rb
dynflow-0.8.10 lib/dynflow/action/progress.rb
dynflow-0.8.9 lib/dynflow/action/progress.rb
dynflow-0.8.8 lib/dynflow/action/progress.rb
dynflow-0.8.7 lib/dynflow/action/progress.rb
dynflow-0.8.6 lib/dynflow/action/progress.rb
dynflow-0.8.5 lib/dynflow/action/progress.rb
dynflow-0.8.4 lib/dynflow/action/progress.rb
dynflow-0.8.3 lib/dynflow/action/progress.rb
dynflow-0.8.2 lib/dynflow/action/progress.rb
dynflow-0.8.1 lib/dynflow/action/progress.rb
dynflow-0.8.0 lib/dynflow/action/progress.rb
dynflow-0.7.9 lib/dynflow/action/progress.rb
dynflow-0.7.8 lib/dynflow/action/progress.rb
dynflow-0.7.7 lib/dynflow/action/progress.rb