em-pg-client 0.2.0.pre.1 → 0.2.0.pre.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. data/HISTORY.rdoc +8 -1
  2. data/em-pg-client.gemspec +1 -1
  3. data/lib/pg/em.rb +24 -11
  4. metadata +1 -1
data/HISTORY.rdoc CHANGED
@@ -1,10 +1,17 @@
1
- next release
1
+ 0.2.0.pre.2
2
+ - errors from consume_input fails deferrable
3
+ - query_timeout now measures only network response timeout,
4
+ so it's not fired for large datasets
5
+
6
+ 0.2.0.pre.1
7
+ - added query_timeout feature for async query commands
2
8
  - added connect_timeout property with for async connect/reset
3
9
  - fix: async_autoreconnect for tcp/ip connections
4
10
  - fix: async_* does not raise errors; errors handled by deferrable
5
11
  - rework async_autoreconnect in fully async manner
6
12
  - added async_connect() and #async_reset()
7
13
  - API change: on_reconnect -> on_autoreconnect
14
+
8
15
  0.1.1
9
16
  - added on_reconnect callback
10
17
  - docs updated
data/em-pg-client.gemspec CHANGED
@@ -2,7 +2,7 @@ $:.unshift "lib"
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = "em-pg-client"
5
- s.version = "0.2.0.pre.1"
5
+ s.version = "0.2.0.pre.2"
6
6
  s.required_ruby_version = ">= 1.9.1"
7
7
  s.date = "#{Time.now.strftime("%Y-%m-%d")}"
8
8
  s.summary = "EventMachine PostgreSQL client"
data/lib/pg/em.rb CHANGED
@@ -135,31 +135,44 @@ module PG
135
135
  @deferrable = deferrable
136
136
  @send_proc = send_proc
137
137
  if (timeout = client.query_timeout) > 0
138
- @timer = ::EM::Timer.new(timeout) do
138
+ @notify_timestamp = Time.now
139
+ setup_timer timeout
140
+ else
141
+ @timer = nil
142
+ end
143
+ end
144
+
145
+ def setup_timer(timeout, adjustment = 0)
146
+ @timer = ::EM::Timer.new(timeout - adjustment) do
147
+ if (last_interval = Time.now - @notify_timestamp) >= timeout
139
148
  detach
140
149
  @client.async_command_aborted = true
141
150
  IO.for_fd(@client.socket).close # break connection now (hack)
142
151
  @deferrable.protect do
143
152
  raise PG::Error, "query timeout expired (async)"
144
153
  end
154
+ else
155
+ setup_timer timeout, last_interval
145
156
  end
146
157
  end
147
158
  end
148
159
 
149
160
  def notify_readable
161
+ @notify_timestamp = Time.now if @timer
150
162
  @client.consume_input
151
- return if @client.is_busy
152
- @timer.cancel if @timer
153
- detach
154
- begin
155
- result = @client.get_last_result
156
- rescue PG::Error => e
157
- @client.async_autoreconnect!(@deferrable, e, &@send_proc)
158
- rescue Exception => e
159
- @deferrable.fail(e)
163
+ result = if @client.is_busy
164
+ false
160
165
  else
161
- @deferrable.succeed(result)
166
+ @timer.cancel if @timer
167
+ detach
168
+ @client.get_last_result
162
169
  end
170
+ rescue PG::Error => e
171
+ @client.async_autoreconnect!(@deferrable, e, &@send_proc)
172
+ rescue Exception => e
173
+ @deferrable.fail(e)
174
+ else
175
+ @deferrable.succeed(result) unless result == false
163
176
  end
164
177
  end
165
178
 
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: em-pg-client
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease: 6
5
- version: 0.2.0.pre.1
5
+ version: 0.2.0.pre.2
6
6
  platform: ruby
7
7
  authors:
8
8
  - Rafal Michalski