[ARVADOS] created: 6a0170aabec325291261d6e1a8fe9f49a469084b
git at public.curoverse.com
git at public.curoverse.com
Tue Jan 21 19:20:58 EST 2014
at 6a0170aabec325291261d6e1a8fe9f49a469084b (commit)
commit 6a0170aabec325291261d6e1a8fe9f49a469084b
Author: Tim Pierce <twp at curoverse.com>
Date: Tue Jan 21 19:19:49 2014 -0500
Cache the API discovery doc for at least 24 hours (refs #1923)
diff --git a/sdk/cli/bin/arv b/sdk/cli/bin/arv
index 3955c94..62b22ca 100755
--- a/sdk/cli/bin/arv
+++ b/sdk/cli/bin/arv
@@ -4,6 +4,8 @@
#
# Ward Vandewege <ward at clinicalfuture.com>
+require 'fileutils'
+
if RUBY_VERSION < '1.9.3' then
abort <<-EOS
#{$0.gsub(/^\.\//,'')} requires Ruby version 1.9.3 or higher.
@@ -116,15 +118,23 @@ end
class Google::APIClient
def discovery_document(api, version)
- api = api.to_s
- return @discovery_documents["#{api}:#{version}"] ||= (begin
- response = self.execute!(
- :http_method => :get,
- :uri => self.discovery_uri(api, version),
- :authenticated => false
- )
- response.body.class == String ? JSON.parse(response.body) : response.body
- end)
+ api = api.to_s
+ return @discovery_documents["#{api}:#{version}"] ||=
+ begin
+ # fetch new API discovery doc if stale
+ cached_doc = File.expand_path '~/.cache/arvados/discovery_uri.json'
+ if not File.exist?(cached_doc) or (Time.now - File.mtime(cached_doc)) > 86400
+ response = self.execute!(:http_method => :get,
+ :uri => self.discovery_uri(api, version),
+ :authenticated => false)
+ FileUtils.makedirs(File.dirname cached_doc)
+ File.open(cached_doc, 'w') do |f|
+ f.puts response.body
+ end
+ end
+
+ File.open(cached_doc) { |f| JSON.load f }
+ end
end
end
diff --git a/sdk/ruby/lib/arvados.rb b/sdk/ruby/lib/arvados.rb
index 5be1fd9..f8bb4c0 100644
--- a/sdk/ruby/lib/arvados.rb
+++ b/sdk/ruby/lib/arvados.rb
@@ -2,6 +2,7 @@ require 'rubygems'
require 'google/api_client'
require 'active_support/inflector'
require 'json'
+require 'fileutils'
ActiveSupport::Inflector.inflections do |inflect|
inflect.irregular 'specimen', 'specimens'
@@ -109,12 +110,19 @@ class Arvados
api = api.to_s
return @discovery_documents["#{api}:#{version}"] ||=
begin
- response = self.execute!(
- :http_method => :get,
- :uri => self.discovery_uri(api, version),
- :authenticated => false
- )
- response.body.class == String ? JSON.parse(response.body) : response.body
+ # fetch new API discovery doc if stale
+ cached_doc = File.expand_path '~/.cache/arvados/discovery_uri.json'
+ if not File.exist?(cached_doc) or (Time.now - File.mtime(cached_doc)) > 86400
+ response = self.execute!(:http_method => :get,
+ :uri => self.discovery_uri(api, version),
+ :authenticated => false)
+ FileUtils.makedirs(File.dirname cached_doc)
+ File.open(cached_doc, 'w') do |f|
+ f.puts response.body
+ end
+ end
+
+ File.open(cached_doc) { |f| JSON.load f }
end
end
end
-----------------------------------------------------------------------
hooks/post-receive
--
More information about the arvados-commits
mailing list