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-1.3.0 lib/dynflow/action/progress.rb
dynflow-1.2.3 lib/dynflow/action/progress.rb
dynflow-1.2.2 lib/dynflow/action/progress.rb
dynflow-1.2.1 lib/dynflow/action/progress.rb
dynflow-1.2.0 lib/dynflow/action/progress.rb
dynflow-1.2.0.pre1 lib/dynflow/action/progress.rb
dynflow-1.1.6 lib/dynflow/action/progress.rb
dynflow-1.1.5 lib/dynflow/action/progress.rb
dynflow-1.1.4 lib/dynflow/action/progress.rb
dynflow-1.1.3 lib/dynflow/action/progress.rb
dynflow-1.1.2 lib/dynflow/action/progress.rb
dynflow-1.1.1 lib/dynflow/action/progress.rb
dynflow-1.1.0 lib/dynflow/action/progress.rb
dynflow-1.0.5 lib/dynflow/action/progress.rb
dynflow-1.0.4 lib/dynflow/action/progress.rb
dynflow-1.0.3 lib/dynflow/action/progress.rb
dynflow-1.0.2 lib/dynflow/action/progress.rb
dynflow-1.0.1 lib/dynflow/action/progress.rb
dynflow-1.0.0 lib/dynflow/action/progress.rb
dynflow-0.8.37 lib/dynflow/action/progress.rb