Class: BiblioTech::Backups::CalendarScheduler

Inherits:
Scheduler
  • Object
show all
Defined in:
lib/bibliotech/backups/calendar_scheduler.rb

Instance Attribute Summary collapse

Attributes inherited from Scheduler

#frequency, #limit, #name

Instance Method Summary collapse

Methods inherited from Scheduler

#freq_seconds, #mark, #range

Constructor Details

#initialize(pattern, limit) ⇒ CalendarScheduler

pattern is an array with minutes rightmost



7
8
9
10
# File 'lib/bibliotech/backups/calendar_scheduler.rb', line 7

def initialize(pattern, limit)
  @pattern = pattern
  super(name_for(pattern), freq_for(pattern), limit)
end

Instance Attribute Details

#patternObject

Returns the value of attribute pattern.



11
12
13
# File 'lib/bibliotech/backups/calendar_scheduler.rb', line 11

def pattern
  @pattern
end

Instance Method Details

#adjustment_indexObject



49
50
51
# File 'lib/bibliotech/backups/calendar_scheduler.rb', line 49

def adjustment_index
  5 - pattern.length
end

#coerce(time, pat = pattern) ⇒ Object

sec, min, hour, day, month, year, wday, yday, isdst, zone

new(year, month, day, hour, min, sec, utc_offset)



55
56
57
58
59
60
# File 'lib/bibliotech/backups/calendar_scheduler.rb', line 55

def coerce(time, pat=pattern)
  existing = time.to_a
  changeable = existing[((pat.length+1)..5)].reverse
  values = changeable + pat + [0, time.utc_offset]
  Time.new(*values) + 1
end

#compute_earliest_time(file_list) ⇒ Object



62
63
64
65
66
67
68
69
70
# File 'lib/bibliotech/backups/calendar_scheduler.rb', line 62

def compute_earliest_time(file_list)
  exact_time = super
  time = coerce(exact_time)
  if time < exact_time
    time
  else
    step_back(time)
  end
end

#freq_for(pattern) ⇒ Object



32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/bibliotech/backups/calendar_scheduler.rb', line 32

def freq_for(pattern)
  case pattern.length
  when 0
    1
  when 1
    60
  when 2
    60 * 24
  when 3
    60 * 24 * 28
  when 4
    60 * 24 * 365
  else
    raise ArgumentError, "argument out of range"
  end
end

#latest_time(file_list) ⇒ Object



72
73
74
75
76
77
78
79
80
# File 'lib/bibliotech/backups/calendar_scheduler.rb', line 72

def latest_time(file_list)
  exact_time = super
  time = coerce(exact_time)
  if time > exact_time
    time
  else
    step_forward(time)
  end
end

#name_for(pattern) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/bibliotech/backups/calendar_scheduler.rb', line 13

def name_for(pattern)
  example_time = coerce(Time.new, pattern)
  case pattern.length
  when 0
    "every-minute"
  when 1
    example_time.strftime('Hourly at :%M')
  when 2
    example_time.strftime('Daily at %H:%M')
  when 3
    example_time.strftime('Monthly on day %d, at %H:%M')
  when 4
    example_time.strftime('Yearly: %b %d, at %H:%M')
  else
    raise ArgumentError, "argument out of range"
  end

end

#step_back(time) ⇒ Object



82
83
84
# File 'lib/bibliotech/backups/calendar_scheduler.rb', line 82

def step_back(time)
  coerce(super(time))
end

#step_forward(time) ⇒ Object



86
87
88
# File 'lib/bibliotech/backups/calendar_scheduler.rb', line 86

def step_forward(time)
  coerce(super(time))
end