forked from concerto/concerto
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathversion_check.rb
26 lines (26 loc) · 1.07 KB
/
version_check.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# Check the latest version of Concerto 2 via remote sources.
module VersionCheck
def self.latest_version
begin
version = Rails.cache.read 'concerto_version'
version_updated = Rails.cache.read 'concerto_version_time'
if !version.nil? && version_updated.is_a?(Time) && !version_updated.nil? # Version is cached.
if version_updated < Time.now - 86400 # Stale (older than 24 hours).
version = Octokit.latest_release('concerto/concerto').tag_name
end
else # Fetch the latest version.
Rails.logger.info 'Downloading latest Concerto version information for the first time.'
begin
version = Octokit.latest_release('concerto/concerto').tag_name
rescue Faraday::ConnectionFailed => e
Rails.logger.error "Unable to fetch Concerto version - #{e.message}"
version = nil
end
end
return version
rescue Octokit::TooManyRequests => e
Rails.logger.error 'Exceeded Github API quota when trying to fetch Concerto version.'
return Concerto::VERSION::STRING
end
end
end