From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from lists.gentoo.org (pigeon.gentoo.org [208.92.234.80]) by finch.gentoo.org (Postfix) with ESMTP id 49E86138247 for ; Thu, 16 Jan 2014 16:43:43 +0000 (UTC) Received: from pigeon.gentoo.org (localhost [127.0.0.1]) by pigeon.gentoo.org (Postfix) with SMTP id 26AE0E0AA1; Thu, 16 Jan 2014 16:43:42 +0000 (UTC) Received: from smtp.gentoo.org (smtp.gentoo.org [140.211.166.183]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by pigeon.gentoo.org (Postfix) with ESMTPS id 82117E0A70 for ; Thu, 16 Jan 2014 16:43:41 +0000 (UTC) Received: from spoonbill.gentoo.org (spoonbill.gentoo.org [81.93.255.5]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by smtp.gentoo.org (Postfix) with ESMTPS id ABD6E33F819 for ; Thu, 16 Jan 2014 16:43:40 +0000 (UTC) Received: from localhost.localdomain (localhost [127.0.0.1]) by spoonbill.gentoo.org (Postfix) with ESMTP id 605941874A for ; Thu, 16 Jan 2014 16:43:39 +0000 (UTC) From: "Alex Legler" To: gentoo-commits@lists.gentoo.org Content-Transfer-Encoding: 8bit Content-type: text/plain; charset=UTF-8 Reply-To: gentoo-dev@lists.gentoo.org, "Alex Legler" Message-ID: <1389439246.cea2c20159abf54d737735db543d0db82fc57bc0.a3li@gentoo> Subject: [gentoo-commits] proj/infra-status:master commit in: lib/ X-VCS-Repository: proj/infra-status X-VCS-Files: lib/service_registry.rb X-VCS-Directories: lib/ X-VCS-Committer: a3li X-VCS-Committer-Name: Alex Legler X-VCS-Revision: cea2c20159abf54d737735db543d0db82fc57bc0 X-VCS-Branch: master Date: Thu, 16 Jan 2014 16:43:39 +0000 (UTC) Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-Id: Gentoo Linux mail X-BeenThere: gentoo-commits@lists.gentoo.org X-Archives-Salt: 95c51757-15df-4a37-8cc9-db3f328e9e6b X-Archives-Hash: 0f01e311191441379b2ec1a93d4dd485 commit: cea2c20159abf54d737735db543d0db82fc57bc0 Author: Alex Legler a3li li> AuthorDate: Sat Jan 11 11:20:46 2014 +0000 Commit: Alex Legler gentoo org> CommitDate: Sat Jan 11 11:20:46 2014 +0000 URL: http://git.overlays.gentoo.org/gitweb/?p=proj/infra-status.git;a=commit;h=cea2c201 Properly clear the ServiceRegistry cache --- lib/service_registry.rb | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) 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 From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from lists.gentoo.org (pigeon.gentoo.org [208.92.234.80]) by finch.gentoo.org (Postfix) with ESMTP id 688B8138247 for ; Sat, 18 Jan 2014 12:10:48 +0000 (UTC) Received: from pigeon.gentoo.org (localhost [127.0.0.1]) by pigeon.gentoo.org (Postfix) with SMTP id D14F8E0C71; Sat, 18 Jan 2014 12:10:47 +0000 (UTC) Received: from smtp.gentoo.org (smtp.gentoo.org [140.211.166.183]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by pigeon.gentoo.org (Postfix) with ESMTPS id 043E3E0C5A for ; Sat, 18 Jan 2014 12:10:46 +0000 (UTC) Received: from spoonbill.gentoo.org (spoonbill.gentoo.org [81.93.255.5]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by smtp.gentoo.org (Postfix) with ESMTPS id 2C7AD33F94F for ; Sat, 18 Jan 2014 12:10:46 +0000 (UTC) Received: from localhost.localdomain (localhost [127.0.0.1]) by spoonbill.gentoo.org (Postfix) with ESMTP id DE46D1872B for ; Sat, 18 Jan 2014 12:10:44 +0000 (UTC) From: "Alex Legler" To: gentoo-commits@lists.gentoo.org Content-Transfer-Encoding: 8bit Content-type: text/plain; charset=UTF-8 Reply-To: gentoo-dev@lists.gentoo.org, "Alex Legler" Message-ID: <1389439246.cea2c20159abf54d737735db543d0db82fc57bc0.a3li@gentoo> Subject: [gentoo-commits] proj/infra-status:master commit in: lib/ X-VCS-Repository: proj/infra-status X-VCS-Files: lib/service_registry.rb X-VCS-Directories: lib/ X-VCS-Committer: a3li X-VCS-Committer-Name: Alex Legler X-VCS-Revision: cea2c20159abf54d737735db543d0db82fc57bc0 X-VCS-Branch: master Date: Sat, 18 Jan 2014 12:10:44 +0000 (UTC) Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-Id: Gentoo Linux mail X-BeenThere: gentoo-commits@lists.gentoo.org X-Archives-Salt: cd6ed752-9eb6-473d-a5d9-0f2028f345b7 X-Archives-Hash: a8e1dfc4bbfa9f094ef4c170cf991e9c Message-ID: <20140118121044.vlTCUmvN7-MsWqt6ZLt6Qa9Vp3u3BXHX1eEjSTEmtO4@z> commit: cea2c20159abf54d737735db543d0db82fc57bc0 Author: Alex Legler a3li li> AuthorDate: Sat Jan 11 11:20:46 2014 +0000 Commit: Alex Legler gentoo org> CommitDate: Sat Jan 11 11:20:46 2014 +0000 URL: http://git.overlays.gentoo.org/gitweb/?p=proj/infra-status.git;a=commit;h=cea2c201 Properly clear the ServiceRegistry cache --- lib/service_registry.rb | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) 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