Permalink
Browse files

use faraday instead of net/http and add em version

  • Loading branch information...
1 parent 3c92c93 commit 6ed160e7e4211b20f8c7f4ad2bc1afddbe718b42 Jigish Patel committed Jun 29, 2012
Showing with 37 additions and 18 deletions.
  1. +1 −0 Gemfile
  2. +4 −0 Gemfile.lock
  3. +19 −13 lib/quilt.rb
  4. +3 −0 lib/quilt/eventmachine.rb
  5. +3 −2 ruby-quilt.gemspec
  6. +7 −3 test/quilt_test.rb
View
@@ -4,6 +4,7 @@ gem "json"
gem "rake"
gem "popen4"
gem "ecology"
+gem "faraday"
gem "scope", :require => false, :group => :test
gem "simplecov", :require => false, :group => :test
View
@@ -6,9 +6,12 @@ GEM
erubis
multi_json
erubis (2.7.0)
+ faraday (0.8.1)
+ multipart-post (~> 1.1)
json (1.7.3)
minitest (3.2.0)
multi_json (1.3.6)
+ multipart-post (1.1.5)
open4 (1.3.0)
popen4 (0.1.2)
Platform (>= 0.4.0)
@@ -26,6 +29,7 @@ PLATFORMS
DEPENDENCIES
ecology
+ faraday
json
popen4
rake
View
@@ -1,9 +1,9 @@
require 'logger'
require 'json'
-require 'net/http'
require 'popen4'
require 'fileutils'
require 'ecology'
+require 'faraday'
require "#{File.join(File.dirname(__FILE__), "lru_cache")}"
class Quilt
@@ -230,15 +230,13 @@ def get_version(name)
log_error("unable to load from host: #{@config[:remote_host]}, path: #{@config[:remote_path]}")
return nil
end
- port = @config[:remote_port] ? @config[:remote_port].to_i : 80
# Fetch the version
filename = "#{name}#{ARCHIVE_SUFFIX}"
version_dir = File.join(@config[:local_path], name)
begin
- res = Net::HTTP.get_response(@config[:remote_host].to_s,
- File.join(@config[:remote_path].to_s, filename), port)
- if (res.code != "200")
- log_error("no version fetched : #{res.code}")
+ res = fetch_remote(filename)
+ if (res.status.to_i != 200)
+ log_error("no version fetched : #{res.status.to_i}")
return nil
end
FileUtils.mkdir(version_dir) unless File.exists?(version_dir)
@@ -339,21 +337,29 @@ def resolve_dynamic(position, modules, dynamics, version)
"#{(dynamics[position] || '')}#{resolve_dependancies(position, modules, version, {})}"
end
+ def fetch_remote(file)
+ host = @config[:remote_host].to_s
+ port = @config[:remote_port] ? @config[:remote_port].to_i : 80
+ path = File.join(@config[:remote_path].to_s, file)
+ conn = Faraday.new(:url => "http://#{host}:#{port}") do |faraday|
+ faraday.adapter Faraday.default_adapter
+ end
+ conn.get(path)
+ end
+
def health
# return true if no remote info
return [true, nil, nil] if !@config[:remote_host] || !@config[:remote_path]
# fetch health_check.txt from remote URL
- host = @config[:remote_host].to_s
- port = @config[:remote_port] ? @config[:remote_port].to_i : 80
- path = File.join(@config[:remote_path].to_s, 'health_check.txt')
begin
- res = Net::HTTP.get_response(host, path, port)
- if (res.code != "200")
- return [false, "Could not fetch heath check file: http://#{host}:#{port}#{path} - status #{res.code}",
+ res = fetch_remote('health_check.txt')
+ if (res.status.to_i != 200)
+ return [false,
+ "Could not fetch heath check file: #{res.env.url.to_s} - status #{res.status.to_i}",
nil]
end
rescue Exception => e
- return [false, "Could not fetch heath check file: http://#{host}:#{port}#{path} - #{e.message}", e]
+ return [false, "Could not fetch heath check file - #{e.message}", e]
end
[true, nil, nil]
end
@@ -0,0 +1,3 @@
+require 'faraday'
+Faraday.default_adapter = :em_synchrony
+require 'quilt'
View
@@ -1,15 +1,16 @@
Gem::Specification.new do |s|
s.name = 'ruby-quilt'
- s.version = '0.2.1'
+ s.version = '0.2.2'
s.summary = "A File stitcher"
s.description = "A file stitcher that maintains versions and can fetch additional versions from a server."
s.authors = ["Jigish Patel"]
s.email = 'x-device-team@ooyala.com'
- s.files = ["lib/quilt.rb", "lib/lru_cache.rb"]
+ s.files = ["lib/quilt.rb", "lib/lru_cache.rb", "lib/quilt/eventmachine.rb"]
s.homepage = 'http://github.com/ooyala/ruby-quilt'
s.add_runtime_dependency 'json', '~> 1.6', '>= 1.6.6'
s.add_runtime_dependency 'popen4', '~> 0.1', '>= 0.1.2'
s.add_runtime_dependency 'ecology', '~> 0.0', '>= 0.0.14'
+ s.add_runtime_dependency 'faraday', '~> 0.8', '>- 0.8.1'
s.add_development_dependency 'rake', '~> 0.8', '>= 0.8.7'
s.add_development_dependency 'scope', '~> 0.2', '>= 0.2.3'
s.add_development_dependency 'simplecov', '~> 0.5', '>= 0.5.3'
View
@@ -1,8 +1,9 @@
#!/usr/bin/env ruby
require "./test/test_helper"
-require "net/http"
+
require "./lib/quilt"
+require "faraday"
require "webrick"
require "ecology"
@@ -83,8 +84,11 @@ class QuiltTest < Scope::TestCase
count = 0
while (!started && count < 10) # wait a max of 5 seconds for the server to start
begin
- res = Net::HTTP.get_response('localhost', '/health_check.txt', 1337)
- if (res.code == "200" && res.body != nil)
+ conn = Faraday.new(:url => "http://localhost:1337") do |faraday|
+ faraday.adapter Faraday.default_adapter
+ end
+ res = conn.get('/health_check.txt')
+ if (res.status.to_i == 200 && res.body != nil)
started = true
end
rescue Exception => e

0 comments on commit 6ed160e

Please sign in to comment.