Class: HaveAPI::Fs::Cleaner
Overview
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
Instance Method Summary collapse
-
#initialize(fs, root) ⇒ Cleaner
constructor
A new instance of Cleaner.
- #start_delay ⇒ Object
- #sweep(component) ⇒ Object
- #work ⇒ Object
- #work_period ⇒ Object
Methods inherited from Worker
#last_time, #next_time, #start, #stop
Constructor Details
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 |