Class: BiblioTech::Backups::Scheduler
- Inherits:
-
Object
- Object
- BiblioTech::Backups::Scheduler
- Defined in:
- lib/bibliotech/backups/scheduler.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#frequency ⇒ Object
Returns the value of attribute frequency.
-
#limit ⇒ Object
Returns the value of attribute limit.
-
#name ⇒ Object
Returns the value of attribute name.
Instance Method Summary collapse
-
#compute_earliest_time(file_list) ⇒ Object
The earliest possible time to keep a file in.
- #freq_seconds ⇒ Object
-
#initialize(name, frequency, limit) ⇒ Scheduler
constructor
A new instance of Scheduler.
-
#latest_time(file_list) ⇒ Object
The latest possible time to keep a file in.
-
#mark(original_file_list) ⇒ Object
Working from the latest time backwards, mark the closest file to the appropriate frequencies as keepable.
- #range ⇒ Object
- #step_back(time) ⇒ Object
- #step_forward(time) ⇒ Object
Constructor Details
#initialize(name, frequency, limit) ⇒ Scheduler
Returns a new instance of Scheduler.
8 9 10 11 12 |
# File 'lib/bibliotech/backups/scheduler.rb', line 8 def initialize(name, frequency, limit) @name = name @frequency, @limit = frequency, limit @limit = nil if limit == "all" end |
Instance Attribute Details
#frequency ⇒ Object
Returns the value of attribute frequency.
6 7 8 |
# File 'lib/bibliotech/backups/scheduler.rb', line 6 def frequency @frequency end |
#limit ⇒ Object
Returns the value of attribute limit.
6 7 8 |
# File 'lib/bibliotech/backups/scheduler.rb', line 6 def limit @limit end |
#name ⇒ Object
Returns the value of attribute name.
6 7 8 |
# File 'lib/bibliotech/backups/scheduler.rb', line 6 def name @name end |
Instance Method Details
#compute_earliest_time(file_list) ⇒ Object
The earliest possible time to keep a file in.
23 24 25 26 27 28 29 30 |
# File 'lib/bibliotech/backups/scheduler.rb', line 23 def compute_earliest_time(file_list) limit_time = Time.at(0) return limit_time if file_list.empty? unless limit.nil? limit_time = latest_time(file_list) - limit * freq_seconds end [limit_time, file_list.last. - range].max end |
#freq_seconds ⇒ Object
14 15 16 |
# File 'lib/bibliotech/backups/scheduler.rb', line 14 def freq_seconds frequency * 60 end |
#latest_time(file_list) ⇒ Object
The latest possible time to keep a file in.
33 34 35 36 |
# File 'lib/bibliotech/backups/scheduler.rb', line 33 def latest_time(file_list) return Time.at(0) if file_list.empty? file_list.first. end |
#mark(original_file_list) ⇒ Object
Working from the latest time backwards, mark the closest file to the appropriate frequencies as keepable
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/bibliotech/backups/scheduler.rb', line 48 def mark(original_file_list) file_list = original_file_list.sort_by{|record| -record..to_i} #sort from newest to oldest time = latest_time(file_list) earliest_time = compute_earliest_time(file_list) oldest_file = file_list.last while time > earliest_time do file_list.delete_if do |record| record. > time end if file_list.empty? oldest_file.in_schedule(name) break end closest = file_list.first if (time - closest.) < freq_seconds closest.in_schedule(name) end time = step_back(time) end return original_file_list end |
#range ⇒ Object
18 19 20 |
# File 'lib/bibliotech/backups/scheduler.rb', line 18 def range freq_seconds / 2 end |
#step_back(time) ⇒ Object
38 39 40 |
# File 'lib/bibliotech/backups/scheduler.rb', line 38 def step_back(time) time - freq_seconds end |
#step_forward(time) ⇒ Object
42 43 44 |
# File 'lib/bibliotech/backups/scheduler.rb', line 42 def step_forward(time) time + freq_seconds end |