From 17aa83ab120cb48d2c12f69e3bfb843308c93e5f Mon Sep 17 00:00:00 2001 From: Kenny Smith Date: Mon, 3 Nov 2014 19:42:23 -0500 Subject: [PATCH 1/5] removing double-loading of json --- lib/blitline.rb | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/lib/blitline.rb b/lib/blitline.rb index 0e82074..698d023 100755 --- a/lib/blitline.rb +++ b/lib/blitline.rb @@ -70,9 +70,8 @@ def poll_job(job_id) url = "/listen/#{job_id}" response = Net::HTTP.get('cache.blitline.com', url) json_response = MultiJson.load(response) - return_results = MultiJson.load(json_response["results"]) - return return_results + return json_response end end From 9ce122bbe631b8cac98294a90160807d0c26b858 Mon Sep 17 00:00:00 2001 From: Kenny Smith Date: Mon, 3 Nov 2014 19:48:15 -0500 Subject: [PATCH 2/5] terminating polling request timeout --- lib/blitline.rb | 35 ++++++++++++++++++++++------------- 1 file changed, 22 insertions(+), 13 deletions(-) diff --git a/lib/blitline.rb b/lib/blitline.rb index 0e82074..500d972 100755 --- a/lib/blitline.rb +++ b/lib/blitline.rb @@ -56,23 +56,32 @@ def post_jobs end def post_job_and_wait_for_poll - validate - raise "'post_job_with_poll' requires that there is only 1 job to submit" unless @jobs.length==1 - result = Blitline::HttpPoster.post("http://#{@domain}.blitline.com/job", { :json => MultiJson.dump(@jobs)}) - json_result = MultiJson.load(result) - raise "Error posting job: #{result.to_s}" if result["error"] - job_id = json_result["results"][0]["job_id"] - return poll_job(job_id) + validate + raise "'post_job_with_poll' requires that there is only 1 job to submit" unless @jobs.length==1 + result = Blitline::HttpPoster.post("http://#{@domain}.blitline.com/job", { :json => MultiJson.dump(@jobs)}) + json_result = MultiJson.load(result) + raise "Error posting job: #{result.to_s}" if result["error"] + job_id = json_result["results"][0]["job_id"] + return poll_job(job_id) end def poll_job(job_id) - raise "Invalid 'job_id'" unless job_id && job_id.length > 0 - url = "/listen/#{job_id}" - response = Net::HTTP.get('cache.blitline.com', url) - json_response = MultiJson.load(response) - return_results = MultiJson.load(json_response["results"]) + raise "Invalid 'job_id'" unless job_id && job_id.length > 0 + url = "/listen/#{job_id}" + + response = {} + + begin + Terminator.terminate 2 do + response = Net::HTTP.get('cache.blitline.com', url) + end + rescue Terminator.error + end + + json_response = MultiJson.load(response) + return_results = MultiJson.load(json_response["results"]) - return return_results + return return_results end end From 37d56b66fa91eb7654e0c7bd09c0e099deeb3c5a Mon Sep 17 00:00:00 2001 From: Kenny Smith Date: Mon, 3 Nov 2014 19:53:29 -0500 Subject: [PATCH 3/5] ignoring built gem --- .gitignore | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.gitignore b/.gitignore index c408757..49eed3a 100644 --- a/.gitignore +++ b/.gitignore @@ -48,3 +48,6 @@ pkg # For rubinius: #*.rbc + +# Ignoring built gem +*.gem From 49dc850c82a4f7215a582132735b19335fe8b524 Mon Sep 17 00:00:00 2001 From: Kenny Smith Date: Mon, 3 Nov 2014 20:19:13 -0500 Subject: [PATCH 4/5] updating tests --- Gemfile | 5 +++-- Gemfile.lock | 8 ++++++++ lib/blitline.rb | 1 + test/helper.rb | 2 ++ test/test_service.rb | 4 ++-- 5 files changed, 16 insertions(+), 4 deletions(-) diff --git a/Gemfile b/Gemfile index 659f71b..c8c4388 100644 --- a/Gemfile +++ b/Gemfile @@ -8,7 +8,8 @@ source "http://rubygems.org" group :development do gem "shoulda", ">= 0" gem "jeweler" + gem "pry" end -gem 'multi_json' -gem 'terminator' \ No newline at end of file +gem "multi_json" +gem "terminator" \ No newline at end of file diff --git a/Gemfile.lock b/Gemfile.lock index 283cce0..d95d066 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -3,6 +3,7 @@ GEM specs: addressable (2.3.5) builder (3.2.2) + coderay (1.1.0) faraday (0.7.6) addressable (~> 2.2) multipart-post (~> 1.1) @@ -26,6 +27,7 @@ GEM rake rdoc json (1.8.1) + method_source (0.8.2) mini_portile (0.5.2) multi_json (1.3.6) multipart-post (1.2.0) @@ -34,11 +36,16 @@ GEM oauth2 (0.5.2) faraday (~> 0.7) multi_json (~> 1.0) + pry (0.10.1) + coderay (~> 1.1.0) + method_source (~> 0.8.1) + slop (~> 3.4) rack (1.5.2) rake (10.1.1) rdoc (4.1.1) json (~> 1.4) shoulda (2.11.3) + slop (3.6.0) terminator (1.0.0) fattr (>= 2.2) @@ -48,5 +55,6 @@ PLATFORMS DEPENDENCIES jeweler multi_json + pry shoulda terminator diff --git a/lib/blitline.rb b/lib/blitline.rb index 9304832..3c59f07 100755 --- a/lib/blitline.rb +++ b/lib/blitline.rb @@ -7,6 +7,7 @@ class Blitline require 'blitline/s3_destination' require 'blitline/http_poster' require 'net/http' + require 'terminator' include AttributeJsonizer attr_accessor :jobs diff --git a/test/helper.rb b/test/helper.rb index 20df5d4..1e8ee70 100644 --- a/test/helper.rb +++ b/test/helper.rb @@ -1,5 +1,6 @@ require 'rubygems' require 'bundler' + begin Bundler.setup(:default, :development) rescue Bundler::BundlerError => e @@ -9,6 +10,7 @@ end require 'test/unit' require 'shoulda' +require 'pry' $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib')) $LOAD_PATH.unshift(File.dirname(__FILE__)) diff --git a/test/test_service.rb b/test/test_service.rb index a1d901f..3c3890a 100755 --- a/test/test_service.rb +++ b/test/test_service.rb @@ -61,7 +61,7 @@ class TestService < Test::Unit::TestCase returned_values = blitline.post_job_and_wait_for_poll assert(returned_values.length > 0, "No results returned") - assert(returned_values['images'].length > 0, "No images returned") + assert(returned_values['results']['images'].length > 0, "No images returned") end should "be able to handle incorrect JSON" do @@ -85,7 +85,7 @@ class TestService < Test::Unit::TestCase returned_values = blitline.post_job_and_wait_for_poll assert(returned_values.length > 0, "No results returned") - assert(returned_values['images'].length > 0, "No images returned") + assert(returned_values['results']['images'].length > 0, "No images returned") end should "be able to commit a job with multiple embedded functions" do From 68f3cf12f61cd9d384655447b02cfa0035e0b13b Mon Sep 17 00:00:00 2001 From: Kenny Smith Date: Mon, 3 Nov 2014 20:39:53 -0500 Subject: [PATCH 5/5] fixing canned polling response to be a valid/empty json string --- lib/blitline.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/blitline.rb b/lib/blitline.rb index 3c59f07..b77318c 100755 --- a/lib/blitline.rb +++ b/lib/blitline.rb @@ -70,7 +70,7 @@ def poll_job(job_id) raise "Invalid 'job_id'" unless job_id && job_id.length > 0 url = "/listen/#{job_id}" - response = {} + response = "{}" begin Terminator.terminate 2 do