google-cloud-pubsub 0.30.1 → 0.30.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8bc2cbfb8b149d600fbdf725934ccef18019853c3c371d34d964a47532640b33
|
4
|
+
data.tar.gz: 836fae2f33841cd070137fab258d208b456018214a25335f6e7848b1c9e0270b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 55cf18d0b63d2f68f28db33f85dd21ded29e960e3cd871278b9abfedfa86829b49e3ea6ba96a7ad1fad15f96da65a2d75fb3f9c2dcd59025f1aba753878a79ca
|
7
|
+
data.tar.gz: ce9772ea6d63bc664739c58ee56c32f84c44f9662c6ba9800a9aacd1a7e09eea9757649ca3290f8db894a07a4401ec4fd9f9573d5c4c7230b8e91ac0141c5fb1
|
@@ -285,16 +285,20 @@ module Google
|
|
285
285
|
@publisher = publisher
|
286
286
|
@messages = []
|
287
287
|
@callbacks = []
|
288
|
+
@total_message_bytes = publisher.topic_name.bytesize + 2
|
288
289
|
end
|
289
290
|
|
290
291
|
def add msg, callback
|
291
292
|
@messages << msg
|
292
293
|
@callbacks << callback
|
294
|
+
@total_message_bytes += msg.to_proto.bytesize + 2
|
293
295
|
end
|
294
296
|
|
295
297
|
def try_add msg, callback
|
296
|
-
|
297
|
-
|
298
|
+
new_message_count = total_message_count + 1
|
299
|
+
new_message_bytes = total_message_bytes + msg.to_proto.bytesize + 2
|
300
|
+
if new_message_count > @publisher.max_messages ||
|
301
|
+
new_message_bytes >= @publisher.max_bytes
|
298
302
|
return false
|
299
303
|
end
|
300
304
|
add msg, callback
|
@@ -311,7 +315,7 @@ module Google
|
|
311
315
|
end
|
312
316
|
|
313
317
|
def total_message_bytes
|
314
|
-
@
|
318
|
+
@total_message_bytes
|
315
319
|
end
|
316
320
|
|
317
321
|
def items
|
@@ -162,39 +162,57 @@ module Google
|
|
162
162
|
def initialize max_bytes: 10000000
|
163
163
|
@max_bytes = max_bytes
|
164
164
|
@request = Google::Pubsub::V1::StreamingPullRequest.new
|
165
|
+
@total_message_bytes = 0
|
165
166
|
end
|
166
167
|
|
167
168
|
def ack ack_id
|
168
169
|
@request.ack_ids << ack_id
|
170
|
+
@total_message_bytes += addl_ack_bytes ack_id
|
169
171
|
end
|
170
172
|
|
171
173
|
def try_ack ack_id
|
172
|
-
addl_bytes = ack_id
|
174
|
+
addl_bytes = addl_ack_bytes ack_id
|
173
175
|
return false if total_message_bytes + addl_bytes >= @max_bytes
|
174
176
|
|
175
177
|
ack ack_id
|
176
178
|
true
|
177
179
|
end
|
178
180
|
|
181
|
+
def addl_ack_bytes ack_id
|
182
|
+
ack_id.bytesize + 2
|
183
|
+
end
|
184
|
+
|
179
185
|
def delay deadline, ack_id
|
180
186
|
@request.modify_deadline_seconds << deadline
|
181
187
|
@request.modify_deadline_ack_ids << ack_id
|
188
|
+
@total_message_bytes += addl_delay_bytes deadline, ack_id
|
182
189
|
end
|
183
190
|
|
184
191
|
def try_delay deadline, ack_id
|
185
|
-
addl_bytes = deadline
|
192
|
+
addl_bytes = addl_delay_bytes deadline, ack_id
|
186
193
|
return false if total_message_bytes + addl_bytes >= @max_bytes
|
187
194
|
|
188
195
|
delay deadline, ack_id
|
189
196
|
true
|
190
197
|
end
|
191
198
|
|
199
|
+
def addl_delay_bytes deadline, ack_id
|
200
|
+
bytes_for_int(deadline) + ack_id.bytesize + 4
|
201
|
+
end
|
202
|
+
|
203
|
+
def bytes_for_int num
|
204
|
+
# Ruby 2.0 does not have Integer#bit_length
|
205
|
+
return [num].pack("s").bytesize unless num.respond_to? :bit_length
|
206
|
+
|
207
|
+
(num.bit_length / 8.0).ceil
|
208
|
+
end
|
209
|
+
|
192
210
|
def ready?
|
193
211
|
total_message_bytes >= @max_bytes
|
194
212
|
end
|
195
213
|
|
196
214
|
def total_message_bytes
|
197
|
-
|
215
|
+
@total_message_bytes
|
198
216
|
end
|
199
217
|
end
|
200
218
|
end
|
@@ -230,16 +230,27 @@ module Google
|
|
230
230
|
break
|
231
231
|
end
|
232
232
|
end
|
233
|
+
# Has the loop broken but we aren't stopped?
|
234
|
+
# Could be GRPC has thrown an internal error, so restart.
|
235
|
+
synchronize { raise "restart thread" unless @stopped }
|
233
236
|
rescue GRPC::DeadlineExceeded, GRPC::Unavailable, GRPC::Cancelled,
|
234
|
-
GRPC::ResourceExhausted, GRPC::Internal
|
237
|
+
GRPC::ResourceExhausted, GRPC::Internal, GRPC::Core::CallError
|
235
238
|
# The GAPIC layer will raise DeadlineExceeded when stream is opened
|
236
239
|
# longer than the timeout value it is configured for. When this
|
237
240
|
# happends, restart the stream stealthly.
|
238
241
|
# Also stealthly restart the stream on Unavailable, Cancelled,
|
239
242
|
# ResourceExhausted, and Internal.
|
243
|
+
# Also, also stealthly restart the stream when GRPC raises the
|
244
|
+
# internal CallError.
|
240
245
|
synchronize { start_streaming! }
|
241
246
|
rescue StandardError => e
|
242
|
-
|
247
|
+
synchronize do
|
248
|
+
if @stopped
|
249
|
+
raise Google::Cloud::Error.from_error(e)
|
250
|
+
else
|
251
|
+
start_streaming!
|
252
|
+
end
|
253
|
+
end
|
243
254
|
end
|
244
255
|
|
245
256
|
# rubocop:enable all
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: google-cloud-pubsub
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.30.
|
4
|
+
version: 0.30.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Mike Moore
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2018-
|
12
|
+
date: 2018-04-02 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: google-cloud-core
|