aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlex Young <alex@bytemark.co.uk>2015-04-20 16:14:03 +0100
committerAlex Young <alex@bytemark.co.uk>2015-04-20 16:14:03 +0100
commit3e986ecfc544b94f329e35ae5b771f68ed27851a (patch)
treef2e32b811ae765c2481c9c64cbdfc91b91033016
parent0a42bb136dc6ccbbf36500d4cc50441681178867 (diff)
Pull the bank holidays cache out to its own class
-rw-r--r--lib/mauve/bank_holidays_cache.rb28
-rw-r--r--lib/mauve/server.rb16
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]