class HaveAPI::Fs::Cleaner

Cleaner is in a regular interval deleting old components from the tree.

A component is declared old when either it's ctime is older than {CTIME} seconds or it's atime is older than {ATIME} seconds. Bound components are not touched.

Constants

ATIME

Delete components not accessed in the last 10 minutes

CTIME

Delete components created more than 30 minutes ago

Public Class Methods

new(fs, root) click to toggle source
Calls superclass method
# File lib/haveapi/fs/cleaner.rb, line 16
def initialize(fs, root)
  super(fs)
  @root = root
  @sweep_id = true
end

Public Instance Methods

start_delay() click to toggle source
# File lib/haveapi/fs/cleaner.rb, line 22
def start_delay
  ATIME + 30
end
sweep(component) click to toggle source
# File lib/haveapi/fs/cleaner.rb, line 39
def sweep(component)
  component.send(:children).delete_if do |_, c|
    sweep(c) unless c.file?

    if !c.bound? && (c.ctime < @ctime || c.atime < @atime)
      if c.unsaved?(@sweep_id ? 1 : 0)
        puts "cannot free unsaved '#{c.path}'"
        next(false)

      else
        c.invalidate
        next(true)
      end
    end
  end
end
work() click to toggle source
# File lib/haveapi/fs/cleaner.rb, line 30
def work
  t = Time.now
  @atime = t - ATIME
  @ctime = t - CTIME

  sweep(@root)
  @sweep_id = !@sweep_id
end
work_period() click to toggle source
# File lib/haveapi/fs/cleaner.rb, line 26
def work_period
  ATIME / 2
end