diff options
author | 2014-01-11 12:20:46 +0100 | |
---|---|---|
committer | 2014-01-11 12:20:46 +0100 | |
commit | cea2c20159abf54d737735db543d0db82fc57bc0 (patch) | |
tree | 71545210a95ba82cc989b65c43dc7ee4a13e117c /lib | |
parent | Remove header buttons on XS screens (diff) | |
download | infra-status-cea2c20159abf54d737735db543d0db82fc57bc0.tar.gz infra-status-cea2c20159abf54d737735db543d0db82fc57bc0.tar.bz2 infra-status-cea2c20159abf54d737735db543d0db82fc57bc0.zip |
Properly clear the ServiceRegistry cache
Diffstat (limited to 'lib')
-rw-r--r-- | lib/service_registry.rb | 20 |
1 files changed, 19 insertions, 1 deletions
diff --git a/lib/service_registry.rb b/lib/service_registry.rb index 61e51c5..d3980a2 100644 --- a/lib/service_registry.rb +++ b/lib/service_registry.rb @@ -65,11 +65,11 @@ module HelperMethods end class ServiceRegistry + CACHE_SECONDS = 600 StatusSource = File.join(File.dirname(__FILE__), '..', 'data', 'status.json') include Singleton include HelperMethods - attr_reader :services, :status_data def initialize end @@ -78,10 +78,28 @@ class ServiceRegistry @services[name] = block.call end + def services + update? + @services + end + + def status_data + update? + @status_data + end + def update! @services = {} @status_data = JSON.parse(File.read(StatusSource)) load(File.join(File.dirname(__FILE__), '..', 'data', 'services.rb')) + @load_date = DateTime.now + end + + private + def update? + if ((DateTime.now - @load_date) * 60 * 60 * 24).to_i > CACHE_SECONDS + update! + end end end |