diff options
Diffstat (limited to 'lib/mauve')
-rw-r--r-- | lib/mauve/bank_holidays_cache.rb | 28 | ||||
-rw-r--r-- | lib/mauve/server.rb | 16 |
2 files changed, 31 insertions, 13 deletions
diff --git a/lib/mauve/bank_holidays_cache.rb b/lib/mauve/bank_holidays_cache.rb new file mode 100644 index 0000000..ce50663 --- /dev/null +++ b/lib/mauve/bank_holidays_cache.rb @@ -0,0 +1,28 @@ +require 'mauve/calendar_interface' + +module Mauve + + class BankHolidaysCache + def initialize + @bank_holidays = [] + @last_checked_at = nil + end + + def bank_holidays + now = Time.now + # + # Update the bank holidays list hourly. + # + if @bank_holidays.nil? or + @last_checked_at.nil? or + @last_checked_at < (now - 1.hour) + + @bank_holidays = CalendarInterface.get_bank_holiday_list(now) + @last_checked_at = now + end + + @bank_holidays + end + end # class BankHolidaysCache + +end # module Mauve diff --git a/lib/mauve/server.rb b/lib/mauve/server.rb index 90d5e77..7ce5823 100644 --- a/lib/mauve/server.rb +++ b/lib/mauve/server.rb @@ -13,6 +13,7 @@ require 'mauve/processor' require 'mauve/http_server' require 'mauve/heartbeat' require 'mauve/configuration' +require 'mauve/bank_holidays_cache' require 'log4r' module Mauve @@ -52,7 +53,7 @@ module Mauve # Bank Holidays -- this list is kept here, because I can't think of # anywhere else to put it. # - @bank_holidays = nil + @bank_holidays_cache = BankHolidaysCache.new # # Turn off unwanted reverse DNS lookups across the board. @@ -127,18 +128,7 @@ module Mauve # # def bank_holidays - # - # Update the bank holidays list hourly. - # - if @bank_holidays.nil? or - @bank_holidays_last_checked_at.nil? or - @bank_holidays_last_checked_at < (Time.now - 1.hour) - - @bank_holidays = CalendarInterface.get_bank_holiday_list(Time.now) - @bank_holidays_last_checked_at = Time.now - end - - @bank_holidays + @bank_holidays_cache.bank_holidays end # return [Log4r::Logger] |