arya-pandemic 0.4.5 → 0.4.6

Sign up to get free protection for your applications and to get access to all the features.
data/Rakefile CHANGED
@@ -2,7 +2,7 @@ require 'rubygems'
2
2
  require 'rake'
3
3
  require 'echoe'
4
4
 
5
- Echoe.new('pandemic', '0.4.5') do |p|
5
+ Echoe.new('pandemic', '0.4.6') do |p|
6
6
  p.description = "A framework for distributing work for real-time services and offline tasks."
7
7
  p.url = "https://github.com/arya/pandemic/"
8
8
  p.author = "Arya Asemanfar"
@@ -5,6 +5,8 @@ module Pandemic
5
5
  class NoNodesAvailable < StandardError; end
6
6
  class LostConnectionToNode < StandardError; end
7
7
  class NodeTimedOut < StandardError; end
8
+ class RequestFailed < StandardError; end
9
+
8
10
 
9
11
  include Util
10
12
  def initialize
@@ -58,8 +60,10 @@ module Pandemic
58
60
  is_ready = IO.select([socket], nil, nil, @response_timeout)
59
61
  raise NodeTimedOut if is_ready.nil?
60
62
  response_size = socket.gets
61
- if response_size
62
- socket.read(response_size.strip.to_i)
63
+ if response_size && response_size.to_i >= 0
64
+ socket.read(response_size.to_i)
65
+ elsif response_size && response_size.to_i < 0
66
+ raise RequestFailed
63
67
  else
64
68
  # nil response size
65
69
  raise LostConnectionToNode
@@ -44,13 +44,20 @@ module Pandemic
44
44
  end
45
45
  else
46
46
  response = handle_request(body)
47
-
48
- debug("Writing response to client")
49
-
50
- # the connection could be closed, we'll let it be rescued if it is.
51
- @connection.write("#{response.size}\n#{response}")
52
- @connection.flush
53
- debug("Finished writing response to client")
47
+ if response
48
+ debug("Writing response to client")
49
+
50
+ # the connection could be closed, we'll let it be rescued if it is.
51
+ @connection.write("#{response.size}\n#{response}")
52
+ @connection.flush
53
+ debug("Finished writing response to client")
54
+ else
55
+ debug("Writing error code to client")
56
+
57
+ @connection.write("-1")
58
+ @connection.flush
59
+ debug("Finished writing error code to client")
60
+ end
54
61
  @responded_requests.inc
55
62
  end
56
63
  end
@@ -84,7 +91,7 @@ module Pandemic
84
91
  @server.handle_client_request(@current_request)
85
92
  rescue Exception => e
86
93
  warn("Unhandled exception in handle client request:\n#{e.inspect}\n#{e.backtrace.join("\n")}")
87
- end
94
+ end || "Error"
88
95
  @current_request = nil
89
96
  return response
90
97
  end
data/pandemic.gemspec CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = %q{pandemic}
5
- s.version = "0.4.5"
5
+ s.version = "0.4.6"
6
6
 
7
7
  s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
8
8
  s.authors = ["Arya Asemanfar"]
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: arya-pandemic
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.5
4
+ version: 0.4.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Arya Asemanfar