Class: Dynflow::Actors::ExecutionPlanCleaner::Core

Inherits:
Dynflow::Actor
  • Object
show all
Defined in:
lib/dynflow/actors/execution_plan_cleaner.rb

Instance Method Summary collapse

Methods inherited from Dynflow::Actor

#behaviour_definition, #finish_termination, #start_termination, #terminating?

Methods included from MethodicActor

#on_message

Methods included from Dynflow::Actor::LogWithFullBacktrace

#log

Constructor Details

#initialize(world, options = {}) ⇒ Core

Returns a new instance of Core.



30
31
32
33
34
35
36
# File 'lib/dynflow/actors/execution_plan_cleaner.rb', line 30

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

Instance Method Details

#clean!Object



43
44
45
46
47
# File 'lib/dynflow/actors/execution_plan_cleaner.rb', line 43

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

#report(plans) ⇒ Object



49
50
51
# File 'lib/dynflow/actors/execution_plan_cleaner.rb', line 49

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

#set_clockObject



53
54
55
# File 'lib/dynflow/actors/execution_plan_cleaner.rb', line 53

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

#startObject



38
39
40
41
# File 'lib/dynflow/actors/execution_plan_cleaner.rb', line 38

def start
  set_clock
  clean!
end