Class: HaveAPI::Fs::Cleaner
Overview
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.
Constant Summary
collapse
- ATIME =
Delete components not accessed in the last 10 minutes
10*60
- CTIME =
Delete components created more than 30 minutes ago
30*60
Instance Attribute Summary
Attributes inherited from Worker
#runs
Instance Method Summary
collapse
Methods inherited from Worker
#last_time, #next_time, #start, #stop
Constructor Details
#initialize(fs, root) ⇒ Cleaner
16
17
18
19
20
|
# File 'lib/haveapi/fs/cleaner.rb', line 16
def initialize(fs, root)
super(fs)
@root = root
@sweep_id = true
end
|
Instance Method Details
#start_delay ⇒ Object
22
23
24
|
# File 'lib/haveapi/fs/cleaner.rb', line 22
def start_delay
ATIME + 30
end
|
#sweep(component) ⇒ Object
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
|
# 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 ⇒ Object
30
31
32
33
34
35
36
37
|
# 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 ⇒ Object
26
27
28
|
# File 'lib/haveapi/fs/cleaner.rb', line 26
def work_period
ATIME / 2
end
|