Sha256: 46677a0c64fb142b67084bfaecb51c32004bd86bf0de924e17b65681f9d3cbc5

Contents?: true

Size: 1.44 KB

Versions: 25

Compression:

Stored size: 1.44 KB

Contents

# frozen_string_literal: true
module Dynflow
  module Actors
    class ExecutionPlanCleaner
      attr_reader :core

      def initialize(world, options = {})
        @world = world
        @options = options
      end

      def core_class
        Core
      end

      def spawn
        Concurrent::Promises.resolvable_future.tap do |initialized|
          @core = core_class.spawn(:name => 'execution-plan-cleaner',
                                   :args => [@world, @options],
                                   :initialized => initialized)
        end
      end

      def clean!
        core.tell([:clean!])
      end

      class Core < Actor
        def initialize(world, options = {})
          @world = world
          default_age = 60 * 60 * 24 # One day by default
          @poll_interval = options.fetch(:poll_interval, default_age)
          @max_age = options.fetch(:max_age, default_age)
          start
        end

        def start
          set_clock
          clean!
        end

        def clean!
          plans = @world.persistence.find_old_execution_plans(Time.now.utc - @max_age)
          report(plans)
          @world.persistence.delete_execution_plans(uuid: plans.map(&:id))
        end

        def report(plans)
          @world.logger.info("Execution plan cleaner removing #{plans.count} execution plans.")
        end

        def set_clock
          @world.clock.ping(self, @poll_interval, :start)
        end
      end
    end
  end
end

Version data entries

25 entries across 25 versions & 1 rubygems

Version Path
dynflow-1.8.2 lib/dynflow/actors/execution_plan_cleaner.rb
dynflow-1.8.1 lib/dynflow/actors/execution_plan_cleaner.rb
dynflow-1.8.0 lib/dynflow/actors/execution_plan_cleaner.rb
dynflow-1.7.0 lib/dynflow/actors/execution_plan_cleaner.rb
dynflow-1.6.11 lib/dynflow/actors/execution_plan_cleaner.rb
dynflow-1.6.10 lib/dynflow/actors/execution_plan_cleaner.rb
dynflow-1.6.8 lib/dynflow/actors/execution_plan_cleaner.rb
dynflow-1.6.7 lib/dynflow/actors/execution_plan_cleaner.rb
dynflow-1.6.6 lib/dynflow/actors/execution_plan_cleaner.rb
dynflow-1.6.5 lib/dynflow/actors/execution_plan_cleaner.rb
dynflow-1.6.4 lib/dynflow/actors/execution_plan_cleaner.rb
dynflow-1.6.3 lib/dynflow/actors/execution_plan_cleaner.rb
dynflow-1.6.2 lib/dynflow/actors/execution_plan_cleaner.rb
dynflow-1.6.1 lib/dynflow/actors/execution_plan_cleaner.rb
dynflow-1.4.9 lib/dynflow/actors/execution_plan_cleaner.rb
dynflow-1.4.8 lib/dynflow/actors/execution_plan_cleaner.rb
dynflow-1.5.0 lib/dynflow/actors/execution_plan_cleaner.rb
dynflow-1.4.7 lib/dynflow/actors/execution_plan_cleaner.rb
dynflow-1.4.6 lib/dynflow/actors/execution_plan_cleaner.rb
dynflow-1.4.5 lib/dynflow/actors/execution_plan_cleaner.rb