google-cloud-pubsub 2.15.1 → 2.15.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: b6f6bca71a506686e481d68852eee2813f5b10908b824089e07bf6ad4070d10a
4
- data.tar.gz: a52f4f7140448a02c2806ed2d7b04a36b1d62f686cb5d0a62dbfce26670165b6
3
+ metadata.gz: b35d78bd1388f589340f93c8e9b9634e06a82406bfeb7cc134f3f9efe9126316
4
+ data.tar.gz: 74c1c0be39fcabaed038750157e891da276e13bb5017c57cbb62ccf542139421
5
5
  SHA512:
6
- metadata.gz: 83662ae6574bf94c38bf19dfc46cda6f6a4fa11b465640ac35794a8ed38f2476244f5be5fb54ef82a1aac90fe4a0b890212e540f5136faaf1b480156d40b2217
7
- data.tar.gz: fded200fa64d0f38a047fa3e2ea5bb3d3c204e8e82748b3611e796e2812809b98281865a923ca33ca2d3086d7c7ef72ca0671656813d77805f49b4b7b32f6e9b
6
+ metadata.gz: 066db5f0cd5bdbd207cf8b928bab86dbb9438d7418ad0a596f07547738311ddb8ead880110e1464aeac7b6a90b44d9b54c36b86d3d873c623c866885c948e62f
7
+ data.tar.gz: 51165f72d1a5813cae65c414915e907b9c15c8e6390ad9ba452b77a42cc6271d6d3b36fc62a97477bed12704d09d76993f0757c6cce8711c0f485eda0e5063f5
data/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # Release History
2
2
 
3
+ ### 2.15.2 (2023-03-19)
4
+
5
+ #### Bug Fixes
6
+
7
+ * make batch handle publish interval ([#20913](https://github.com/googleapis/google-cloud-ruby/issues/20913))
8
+
3
9
  ### 2.15.1 (2023-02-23)
4
10
 
5
11
  #### Documentation
@@ -141,7 +141,7 @@ module Google
141
141
 
142
142
  until @queue.empty?
143
143
  item = @queue.first
144
- if try_add item.msg, item.callback
144
+ if try_add item.msg, item.callback, item.create_time
145
145
  @queue.shift
146
146
  next
147
147
  end
@@ -178,12 +178,7 @@ module Google
178
178
  return false
179
179
  end
180
180
 
181
- until @queue.empty?
182
- item = @queue.first
183
- added = try_add item.msg, item.callback
184
- break unless added
185
- @queue.shift
186
- end
181
+ refill_items
187
182
 
188
183
  return false unless @publishing
189
184
  if @items.empty?
@@ -191,6 +186,7 @@ module Google
191
186
  return false
192
187
  else
193
188
  return true if stopping?
189
+ return true if interval_met?(@items.first.create_time) || batch_full_by_count?
194
190
  if @queue.empty?
195
191
  @publishing = false
196
192
  return false
@@ -261,16 +257,33 @@ module Google
261
257
 
262
258
  protected
263
259
 
264
- def items_add msg, callback
265
- item = Item.new msg, callback
260
+ def interval_met? create_time
261
+ Time.now - create_time > @publisher.interval
262
+ end
263
+
264
+ def batch_full_by_count?
265
+ total_message_count == @publisher.max_messages
266
+ end
267
+
268
+ def refill_items
269
+ until @queue.empty?
270
+ item = @queue.first
271
+ added = try_add item.msg, item.callback, item.create_time
272
+ break unless added
273
+ @queue.shift
274
+ end
275
+ end
276
+
277
+ def items_add msg, callback, create_time
278
+ item = Item.new msg, callback, (create_time || Time.now)
266
279
  @items << item
267
280
  @total_message_bytes += item.bytesize + 2
268
281
  end
269
282
 
270
- def try_add msg, callback
283
+ def try_add msg, callback, create_time = nil
271
284
  if @items.empty?
272
285
  # Always add when empty, even if bytesize is bigger than total
273
- items_add msg, callback
286
+ items_add msg, callback, create_time
274
287
  return true
275
288
  end
276
289
  new_message_count = total_message_count + 1
@@ -279,12 +292,12 @@ module Google
279
292
  new_message_bytes >= @publisher.max_bytes
280
293
  return false
281
294
  end
282
- items_add msg, callback
295
+ items_add msg, callback, create_time
283
296
  true
284
297
  end
285
298
 
286
299
  def queue_add msg, callback
287
- item = Item.new msg, callback
300
+ item = Item.new msg, callback, Time.now
288
301
  @queue << item
289
302
  end
290
303
 
@@ -292,7 +305,7 @@ module Google
292
305
  @items.count
293
306
  end
294
307
 
295
- Item = Struct.new :msg, :callback do
308
+ Item = Struct.new :msg, :callback, :create_time do
296
309
  def bytesize
297
310
  msg.to_proto.bytesize
298
311
  end
@@ -16,7 +16,7 @@
16
16
  module Google
17
17
  module Cloud
18
18
  module PubSub
19
- VERSION = "2.15.1".freeze
19
+ VERSION = "2.15.2".freeze
20
20
  end
21
21
 
22
22
  Pubsub = PubSub unless const_defined? :Pubsub
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: 2.15.1
4
+ version: 2.15.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: 2023-02-23 00:00:00.000000000 Z
12
+ date: 2023-03-20 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: concurrent-ruby