Add Redis front-end to existing Ruby server

This commit is contained in:
Buck Doyle 2016-04-14 15:54:05 +02:00
parent 45f90c5ed2
commit 0403884224

View File

@ -5,6 +5,7 @@ require 'delegate'
require 'time'
require 'json'
require 'travis/utils/deep_merge'
require 'redis'
class Travis::Web::App
autoload :AltVersions, 'travis/web/app/alt_versions'
@ -82,7 +83,7 @@ class Travis::Web::App
end
def response_for(file, options = {})
content = File.read(file)
content = content_for(file)
if fingerprinted?(file)
headers = {
'Content-Length' => content.bytesize.to_s,
@ -111,6 +112,17 @@ class Travis::Web::App
[ 200, headers, [content] ]
end
def content_for(file)
if index?(file)
redis = Redis.new
project = 'travis'
index_key = redis.get("#{project}:index:current")
redis.get("#{project}:index:#{index_key}")
else
content = File.read(file)
end
end
def each_file
Dir.glob(File.join(root, '**/*')) { |file| yield file if File.file?(file) }
end