Class: Aebus::Config::BackupSchedule

Inherits:
Object
  • Object
show all
Defined in:
lib/config/volume.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(current_time_utc, label, backup_config) ⇒ BackupSchedule

Returns a new instance of BackupSchedule.



13
14
15
16
17
18
19
20
21
22
# File 'lib/config/volume.rb', line 13

def initialize (current_time_utc, label, backup_config)
  @label = label
  if (backup_config["enabled"]) then
    calculate_deadlines(current_time_utc, backup_config["when"])
  end
  @keep = backup_config["keep"]
  # we use Infinity to model the keep all
  @keep = 1.0 / 0  if (@keep.nil? || @keep.eql?(KEEP_ALL))

end

Instance Attribute Details

#keepObject (readonly)

Returns the value of attribute keep.



11
12
13
# File 'lib/config/volume.rb', line 11

def keep
  @keep
end

#labelObject (readonly)

Returns the value of attribute label.



11
12
13
# File 'lib/config/volume.rb', line 11

def label
  @label
end

#last_deadlineObject (readonly)

Returns the value of attribute last_deadline.



11
12
13
# File 'lib/config/volume.rb', line 11

def last_deadline
  @last_deadline
end

#next_deadlineObject (readonly)

Returns the value of attribute next_deadline.



11
12
13
# File 'lib/config/volume.rb', line 11

def next_deadline
  @next_deadline
end

Class Method Details

.parse_backups_config(current_time_utc, backups_config) ⇒ Object



37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/config/volume.rb', line 37

def self.parse_backups_config(current_time_utc, backups_config)

  return nil unless backups_config

  result = Hash.new

  backups_config.each_pair do |key,value|
    result.store(key, BackupSchedule.new(current_time_utc, key, value))
  end

  result

end

Instance Method Details

#calculate_deadlines(current_time_utc, when_string) ⇒ Object

Raises:

  • (ArgumentError)


24
25
26
27
28
29
30
31
# File 'lib/config/volume.rb', line 24

def calculate_deadlines(current_time_utc, when_string)
  raise(ArgumentError, "when field cannot be empty if the backup is enabled") unless when_string

  parser = CronParser.new (when_string)
  @last_deadline = parser.last(current_time_utc)
  @next_deadline = parser.next(current_time_utc)

end

#to_sObject



33
34
35
# File 'lib/config/volume.rb', line 33

def to_s
  "Backup Schedule:  label => #{@label}  last_deadline => #{@last_deadline} next_deadline => #{@next_deadline}  keep => #{@keep}"
end