Sha256: d5ebbadbd35f5cc0e64a3274281d4d13cfdf025e7ce35b68c76e831523ebd9b9

Contents?: true

Size: 1.58 KB

Versions: 2

Compression:

Stored size: 1.58 KB

Contents

# frozen_string_literal: true

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

2 entries across 2 versions & 1 rubygems

Version Path
dynflow-1.9.0 lib/dynflow/action/progress.rb
dynflow-1.8.3 lib/dynflow/action/progress.rb