google-cloud-pubsub 0.36.0 → 0.37.0

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: e6bdfb3062337b8aaf70394ea5f2c35054ac9cbe83836631b188456b8801c39e
4
- data.tar.gz: 6f51848602a6702095214030780ddeae82e715b364541d2c1b8014232610c6b7
3
+ metadata.gz: ff2481f99b8def0df9c9203a64569dc317907152518da6b522d63314524ebea5
4
+ data.tar.gz: 8773411fca063ab56c81d94951406866747f9137f4c9d9e9860b011412a0bae3
5
5
  SHA512:
6
- metadata.gz: 693140e1add6261c55b61d3a9514db9c10afcf4dd04f0e0d1dd369aabd915aa8dce15eda2408e1d9be6cc9f54d9f546c638eb7d8aa66ca63319dd014e2382536
7
- data.tar.gz: 8872761deb3b50239a4bee8d8ef9259492e5e60259e6a6508f632134e0521443910dc54dd4536c0dc4242a2d40c0fc9e4cb911109a5754aace8c8596f2c36138
6
+ metadata.gz: 47976e8e93c6a68707a24f26b92110fca18eef669c41c86f93cf9d746c55596abbddde9f067a42b47c68c6472d5655616380f0e334623872455d5932b97ffd9c
7
+ data.tar.gz: ebf63bd135e128d19f56c9ece11aad5f1fc8cf2489fa7b8c726ccc68e98632ee4751c28079d9dfc17379dbf40cf9871a44b9d1c03d50dc0b1a6c9215de45f25d
data/CHANGELOG.md CHANGED
@@ -1,5 +1,21 @@
1
1
  # Release History
2
2
 
3
+ ### 0.37.0 / 2019-06-17
4
+
5
+ * Add Topic#persistence_regions
6
+ * Subscriber changes
7
+ * Fix potential inventory bug
8
+ * Messages are removed after callback
9
+ * This change prevents the Subscriber inventory from filling up
10
+ when messages are never acked or nacked in the user callback.
11
+ This might happen due to an error in the user callback code.
12
+ Removing a message from the inventory will cause the message to
13
+ be redelivered and reprocessed.
14
+ * Update concurrency implementation
15
+ * Use concurrent-ruby Promises framework.
16
+ * Update network configuration
17
+ * Enable grpc.service_config_disable_resolution
18
+
3
19
  ### 0.36.0 / 2019-05-21
4
20
 
5
21
  * Add Topic#kms_key
@@ -193,10 +193,10 @@ module Google
193
193
 
194
194
  def init_resources!
195
195
  @first_published_at ||= Time.now
196
- @publish_thread_pool ||= Concurrent::FixedThreadPool.new \
197
- @publish_threads
198
- @callback_thread_pool ||= Concurrent::FixedThreadPool.new \
199
- @callback_threads
196
+ @publish_thread_pool ||= Concurrent::CachedThreadPool.new \
197
+ max_threads: @publish_threads
198
+ @callback_thread_pool ||= Concurrent::CachedThreadPool.new \
199
+ max_threads: @callback_threads
200
200
  @thread ||= Thread.new { run_background }
201
201
  end
202
202
 
@@ -235,33 +235,39 @@ module Google
235
235
  def publish_batch_async topic_name, batch
236
236
  return unless @publish_thread_pool.running?
237
237
 
238
- Concurrent::Future.new executor: @publish_thread_pool do
239
- begin
240
- grpc = @service.publish topic_name, batch.messages
241
- batch.items.zip Array(grpc.message_ids) do |item, id|
242
- next unless item.callback
238
+ Concurrent::Promises.future_on(
239
+ @publish_thread_pool, topic_name, batch
240
+ ) do |t_name, btch|
241
+ publish_batch_sync t_name, btch
242
+ end
243
+ end
243
244
 
244
- item.msg.message_id = id
245
- publish_result = PublishResult.from_grpc item.msg
246
- execute_callback_async item.callback, publish_result
247
- end
248
- rescue StandardError => e
249
- batch.items.each do |item|
250
- next unless item.callback
245
+ def publish_batch_sync topic_name, batch
246
+ grpc = @service.publish topic_name, batch.messages
247
+ batch.items.zip Array(grpc.message_ids) do |item, id|
248
+ next unless item.callback
251
249
 
252
- publish_result = PublishResult.from_error item.msg, e
253
- execute_callback_async item.callback, publish_result
254
- end
255
- end
256
- end.execute
250
+ item.msg.message_id = id
251
+ publish_result = PublishResult.from_grpc item.msg
252
+ execute_callback_async item.callback, publish_result
253
+ end
254
+ rescue StandardError => e
255
+ batch.items.each do |item|
256
+ next unless item.callback
257
+
258
+ publish_result = PublishResult.from_error item.msg, e
259
+ execute_callback_async item.callback, publish_result
260
+ end
257
261
  end
258
262
 
259
263
  def execute_callback_async callback, publish_result
260
264
  return unless @callback_thread_pool.running?
261
265
 
262
- Concurrent::Future.new executor: @callback_thread_pool do
263
- callback.call publish_result
264
- end.execute
266
+ Concurrent::Promises.future_on(
267
+ @callback_thread_pool, callback, publish_result
268
+ ) do |cback, p_result|
269
+ cback.call p_result
270
+ end
265
271
  end
266
272
 
267
273
  def create_pubsub_message data, attributes
@@ -46,9 +46,10 @@ module Google
46
46
  end
47
47
 
48
48
  def chan_args
49
- { "grpc.max_send_message_length" => -1,
50
- "grpc.max_receive_message_length" => -1,
51
- "grpc.keepalive_time_ms" => 300000 }
49
+ { "grpc.max_send_message_length" => -1,
50
+ "grpc.max_receive_message_length" => -1,
51
+ "grpc.keepalive_time_ms" => 300000,
52
+ "grpc.service_config_disable_resolution" => 1 }
52
53
  end
53
54
 
54
55
  def chan_creds
@@ -40,7 +40,8 @@ module Google
40
40
  end
41
41
 
42
42
  def add *ack_ids
43
- ack_ids.flatten!.compact!
43
+ ack_ids.flatten!
44
+ ack_ids.compact!
44
45
  return if ack_ids.empty?
45
46
 
46
47
  synchronize do
@@ -50,7 +51,8 @@ module Google
50
51
  end
51
52
 
52
53
  def remove *ack_ids
53
- ack_ids.flatten!.compact!
54
+ ack_ids.flatten!
55
+ ack_ids.compact!
54
56
  return if ack_ids.empty?
55
57
 
56
58
  synchronize do
@@ -48,8 +48,8 @@ module Google
48
48
  @pause_cond = new_cond
49
49
 
50
50
  @inventory = Inventory.new self, @subscriber.stream_inventory
51
- @callback_thread_pool = Concurrent::FixedThreadPool.new \
52
- @subscriber.callback_threads
51
+ @callback_thread_pool = Concurrent::CachedThreadPool.new \
52
+ max_threads: @subscriber.callback_threads
53
53
 
54
54
  @stream_keepalive_task = Concurrent::TimerTask.new(
55
55
  execution_interval: 30
@@ -181,21 +181,25 @@ module Google
181
181
  # rubocop:disable all
182
182
 
183
183
  def background_run
184
- # Don't allow a stream to restart if already stopped
185
- return if @stopped
184
+ synchronize do
185
+ # Don't allow a stream to restart if already stopped
186
+ return if @stopped
186
187
 
187
- # signal to the previous queue to shut down
188
- old_queue = []
189
- old_queue = @request_queue.quit_and_dump_queue if @request_queue
188
+ @stopped = false
189
+ @paused = false
190
190
 
191
- # Always create a new request queue and enum
192
- @request_queue = EnumeratorQueue.new self
193
- @request_queue.push initial_input_request
194
- old_queue.each { |obj| @request_queue.push obj }
195
- enum = @subscriber.service.streaming_pull @request_queue.each
191
+ # signal to the previous queue to shut down
192
+ old_queue = []
193
+ old_queue = @request_queue.quit_and_dump_queue if @request_queue
196
194
 
197
- @stopped = nil
198
- @paused = nil
195
+ # Always create a new request queue
196
+ @request_queue = EnumeratorQueue.new self
197
+ @request_queue.push initial_input_request
198
+ old_queue.each { |obj| @request_queue.push obj }
199
+ end
200
+
201
+ # Call the StreamingPull API to get the response enumerator
202
+ enum = @subscriber.service.streaming_pull @request_queue.each
199
203
 
200
204
  loop do
201
205
  synchronize do
@@ -242,7 +246,7 @@ module Google
242
246
  raise RestartStream unless synchronize { @stopped }
243
247
 
244
248
  # We must be stopped, tell the stream to quit.
245
- @request_queue.push self
249
+ stop
246
250
  rescue GRPC::Cancelled, GRPC::DeadlineExceeded, GRPC::Internal,
247
251
  GRPC::ResourceExhausted, GRPC::Unauthenticated,
248
252
  GRPC::Unavailable, GRPC::Core::CallError
@@ -253,10 +257,7 @@ module Google
253
257
  rescue RestartStream
254
258
  retry
255
259
  rescue StandardError => e
256
- synchronize do
257
- @subscriber.error! e
258
- start_streaming! unless @stopped
259
- end
260
+ @subscriber.error! e
260
261
 
261
262
  retry
262
263
  end
@@ -266,13 +267,17 @@ module Google
266
267
  def perform_callback_async rec_msg
267
268
  return unless callback_thread_pool.running?
268
269
 
269
- Concurrent::Future.new executor: callback_thread_pool do
270
+ Concurrent::Promises.future_on(
271
+ callback_thread_pool, @subscriber, @inventory, rec_msg
272
+ ) do |sub, inv, msg|
270
273
  begin
271
- @subscriber.callback.call rec_msg
274
+ sub.callback.call msg
272
275
  rescue StandardError => callback_error
273
- @subscriber.error! callback_error
276
+ sub.error! callback_error
277
+ ensure
278
+ inv.remove msg.ack_id
274
279
  end
275
- end.execute
280
+ end
276
281
  end
277
282
 
278
283
  def start_streaming!
@@ -281,9 +286,6 @@ module Google
281
286
  # could not be recovered from, so be it.
282
287
  return if @background_thread
283
288
 
284
- @stopped = false
285
- @paused = false
286
-
287
289
  # create new background thread to handle new enumerator
288
290
  @background_thread = Thread.new { background_run }
289
291
  end
@@ -187,7 +187,8 @@ module Google
187
187
  end
188
188
 
189
189
  def with_threadpool
190
- pool = Concurrent::FixedThreadPool.new @subscriber.push_threads
190
+ pool = Concurrent::CachedThreadPool.new \
191
+ max_threads: @subscriber.push_threads
191
192
 
192
193
  yield pool
193
194
 
@@ -204,13 +205,13 @@ module Google
204
205
  end
205
206
 
206
207
  def add_future pool
207
- Concurrent::Future.new executor: pool do
208
+ Concurrent::Promises.future_on pool do
208
209
  begin
209
210
  yield
210
211
  rescue StandardError => error
211
212
  error! error
212
213
  end
213
- end.execute
214
+ end
214
215
  end
215
216
  end
216
217
  end
@@ -501,8 +501,12 @@ module Google
501
501
  end
502
502
 
503
503
  ##
504
- # Create a {Subscriber} object that receives and processes messages
505
- # using the code provided in the callback.
504
+ # Create a {Subscriber} object that receives and processes messages
505
+ # using the code provided in the callback. Messages passed to the
506
+ # callback should acknowledge ({ReceivedMessage#acknowledge!}) or reject
507
+ # ({ReceivedMessage#reject!}) the message. If no action is taken, the
508
+ # message will be removed from the subscriber and made available for
509
+ # redelivery after the callback is completed.
506
510
  #
507
511
  # @param [Numeric] deadline The default number of seconds the stream
508
512
  # will hold received messages before modifying the message's ack
@@ -182,6 +182,36 @@ module Google
182
182
  @resource_name = nil
183
183
  end
184
184
 
185
+ ##
186
+ # The list of GCP region IDs where messages that are published to the
187
+ # topic may be persisted in storage.
188
+ #
189
+ # Messages published by publishers running in non-allowed GCP regions
190
+ # (or running outside of GCP altogether) will be routed for storage in
191
+ # one of the allowed regions. An empty list indicates a misconfiguration
192
+ # at the project or organization level, which will result in all publish
193
+ # operations failing.
194
+ #
195
+ # Makes an API call to retrieve the list of GCP region IDs values when
196
+ # called on a reference object. See {#reference?}.
197
+ #
198
+ # @return [Array<String>]
199
+ #
200
+ # @example
201
+ # require "google/cloud/pubsub"
202
+ #
203
+ # pubsub = Google::Cloud::PubSub.new
204
+ #
205
+ # topic = pubsub.topic "my-topic"
206
+ #
207
+ # topic.persistence_regions #=> ["us-central1", "us-central2"]
208
+ #
209
+ def persistence_regions
210
+ ensure_grpc!
211
+ return [] if @grpc.message_storage_policy.nil?
212
+ Array @grpc.message_storage_policy.allowed_persistence_regions
213
+ end
214
+
185
215
  ##
186
216
  # Permanently deletes the topic.
187
217
  #
@@ -28,6 +28,7 @@ require "google/gax"
28
28
  require "google/iam/v1/iam_policy_pb"
29
29
  require "google/pubsub/v1/pubsub_pb"
30
30
  require "google/cloud/pubsub/v1/credentials"
31
+ require "google/cloud/pubsub/version"
31
32
 
32
33
  module Google
33
34
  module Cloud
@@ -182,7 +183,7 @@ module Google
182
183
  updater_proc = credentials.updater_proc
183
184
  end
184
185
 
185
- package_version = Gem.loaded_specs['google-cloud-pubsub'].version.version
186
+ package_version = Google::Cloud::PubSub::VERSION
186
187
 
187
188
  google_api_client = "gl-ruby/#{RUBY_VERSION}"
188
189
  google_api_client << " #{lib_name}/#{lib_version}" if lib_name
@@ -35,7 +35,7 @@
35
35
  "initial_retry_delay_millis": 100,
36
36
  "retry_delay_multiplier": 1.3,
37
37
  "max_retry_delay_millis": 60000,
38
- "initial_rpc_timeout_millis": 12000,
38
+ "initial_rpc_timeout_millis": 25000,
39
39
  "rpc_timeout_multiplier": 1.0,
40
40
  "max_rpc_timeout_millis": 30000,
41
41
  "total_timeout_millis": 600000
@@ -28,6 +28,7 @@ require "google/gax"
28
28
  require "google/iam/v1/iam_policy_pb"
29
29
  require "google/pubsub/v1/pubsub_pb"
30
30
  require "google/cloud/pubsub/v1/credentials"
31
+ require "google/cloud/pubsub/version"
31
32
 
32
33
  module Google
33
34
  module Cloud
@@ -206,7 +207,7 @@ module Google
206
207
  updater_proc = credentials.updater_proc
207
208
  end
208
209
 
209
- package_version = Gem.loaded_specs['google-cloud-pubsub'].version.version
210
+ package_version = Google::Cloud::PubSub::VERSION
210
211
 
211
212
  google_api_client = "gl-ruby/#{RUBY_VERSION}"
212
213
  google_api_client << " #{lib_name}/#{lib_version}" if lib_name
@@ -26,9 +26,9 @@
26
26
  "initial_retry_delay_millis": 100,
27
27
  "retry_delay_multiplier": 1.3,
28
28
  "max_retry_delay_millis": 60000,
29
- "initial_rpc_timeout_millis": 12000,
29
+ "initial_rpc_timeout_millis": 25000,
30
30
  "rpc_timeout_multiplier": 1.0,
31
- "max_rpc_timeout_millis": 12000,
31
+ "max_rpc_timeout_millis": 25000,
32
32
  "total_timeout_millis": 600000
33
33
  },
34
34
  "streaming_messaging": {
@@ -16,7 +16,7 @@
16
16
  module Google
17
17
  module Cloud
18
18
  module PubSub
19
- VERSION = "0.36.0".freeze
19
+ VERSION = "0.37.0".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: 0.36.0
4
+ version: 0.37.0
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: 2019-05-21 00:00:00.000000000 Z
12
+ date: 2019-06-18 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: google-cloud-core
@@ -79,14 +79,14 @@ dependencies:
79
79
  requirements:
80
80
  - - "~>"
81
81
  - !ruby/object:Gem::Version
82
- version: '1.0'
82
+ version: '1.1'
83
83
  type: :runtime
84
84
  prerelease: false
85
85
  version_requirements: !ruby/object:Gem::Requirement
86
86
  requirements:
87
87
  - - "~>"
88
88
  - !ruby/object:Gem::Version
89
- version: '1.0'
89
+ version: '1.1'
90
90
  - !ruby/object:Gem::Dependency
91
91
  name: minitest
92
92
  requirement: !ruby/object:Gem::Requirement