google-cloud-pubsub 0.29.0 → 0.30.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/google-cloud-pubsub.rb +30 -0
- data/lib/google/cloud/pubsub.rb +70 -12
- data/lib/google/cloud/pubsub/async_publisher.rb +2 -2
- data/lib/google/cloud/pubsub/convert.rb +1 -1
- data/lib/google/cloud/pubsub/credentials.rb +6 -6
- data/lib/google/cloud/pubsub/message.rb +4 -3
- data/lib/google/cloud/pubsub/project.rb +13 -23
- data/lib/google/cloud/pubsub/publish_result.rb +3 -3
- data/lib/google/cloud/pubsub/received_message.rb +8 -8
- data/lib/google/cloud/pubsub/service.rb +4 -2
- data/lib/google/cloud/pubsub/snapshot.rb +1 -1
- data/lib/google/cloud/pubsub/snapshot/list.rb +1 -1
- data/lib/google/cloud/pubsub/subscriber.rb +3 -2
- data/lib/google/cloud/pubsub/subscriber/stream.rb +23 -10
- data/lib/google/cloud/pubsub/subscription.rb +12 -11
- data/lib/google/cloud/pubsub/subscription/list.rb +1 -1
- data/lib/google/cloud/pubsub/topic.rb +11 -10
- data/lib/google/cloud/pubsub/topic/list.rb +1 -1
- data/lib/google/cloud/pubsub/version.rb +1 -1
- metadata +9 -9
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7b647f7265e16e47a38c39b2171f2f21823604e384830cd209b2e85b0284a5db
|
4
|
+
data.tar.gz: 62cbd134e8699a48759114fe1437286230b485b7b8598c1ee32823cb66215b80
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e39a2f11dbdace3f1088e3bbc0f4b883a939d0c9d7d0ff8e8978397bfe4fff20f5d162b736df7ed435f03396eb773c817970c55fdf5f414eb0bf4d698749b97f
|
7
|
+
data.tar.gz: 488f6fc246f5cc7f7d108cb7096e94cae4ea8b7680fc7e9e6f062bad987a5705825eaa4456a113f37d5f60823adaefb1c5b3a74fb48e085135a3eb3a98d9ba40
|
data/lib/google-cloud-pubsub.rb
CHANGED
@@ -20,6 +20,8 @@
|
|
20
20
|
|
21
21
|
gem "google-cloud-core"
|
22
22
|
require "google/cloud"
|
23
|
+
require "google/cloud/config"
|
24
|
+
require "googleauth"
|
23
25
|
|
24
26
|
module Google
|
25
27
|
module Cloud
|
@@ -110,3 +112,31 @@ module Google
|
|
110
112
|
end
|
111
113
|
end
|
112
114
|
end
|
115
|
+
|
116
|
+
# Set the default pubsub configuration
|
117
|
+
Google::Cloud.configure.add_config! :pubsub do |config|
|
118
|
+
default_project = Google::Cloud::Config.deferred do
|
119
|
+
ENV["PUBSUB_PROJECT"]
|
120
|
+
end
|
121
|
+
default_creds = Google::Cloud::Config.deferred do
|
122
|
+
Google::Cloud::Config.credentials_from_env(
|
123
|
+
"PUBSUB_CREDENTIALS", "PUBSUB_CREDENTIALS_JSON",
|
124
|
+
"PUBSUB_KEYFILE", "PUBSUB_KEYFILE_JSON"
|
125
|
+
)
|
126
|
+
end
|
127
|
+
default_emulator = Google::Cloud::Config.deferred do
|
128
|
+
ENV["PUBSUB_EMULATOR_HOST"]
|
129
|
+
end
|
130
|
+
|
131
|
+
config.add_field! :project_id, default_project, match: String, allow_nil: true
|
132
|
+
config.add_alias! :project, :project_id
|
133
|
+
config.add_field! :credentials, default_creds,
|
134
|
+
match: [String, Hash, Google::Auth::Credentials],
|
135
|
+
allow_nil: true
|
136
|
+
config.add_alias! :keyfile, :credentials
|
137
|
+
config.add_field! :scope, nil, match: [String, Array]
|
138
|
+
config.add_field! :timeout, nil, match: Integer
|
139
|
+
config.add_field! :client_config, nil, match: Hash
|
140
|
+
config.add_field! :emulator_host, default_emulator,
|
141
|
+
match: String, allow_nil: true
|
142
|
+
end
|
data/lib/google/cloud/pubsub.rb
CHANGED
@@ -15,6 +15,8 @@
|
|
15
15
|
|
16
16
|
require "google-cloud-pubsub"
|
17
17
|
require "google/cloud/pubsub/project"
|
18
|
+
require "google/cloud/config"
|
19
|
+
require "google/cloud/env"
|
18
20
|
|
19
21
|
module Google
|
20
22
|
module Cloud
|
@@ -28,11 +30,14 @@ module Google
|
|
28
30
|
# Cloud Pub/Sub allows developers to communicate between independently
|
29
31
|
# written applications.
|
30
32
|
#
|
31
|
-
# The goal of google-cloud is to provide
|
32
|
-
# Rubyists.
|
33
|
-
#
|
34
|
-
#
|
35
|
-
#
|
33
|
+
# The goal of google-cloud is to provide an API that is comfortable to
|
34
|
+
# Rubyists. Your authentication credentials are detected automatically in
|
35
|
+
# Google Cloud Platform environments such as Google Compute Engine, Google
|
36
|
+
# App Engine and Google Kubernetes Engine. In other environments you can
|
37
|
+
# configure authentication easily, either directly in your code or via
|
38
|
+
# environment variables. Read more about the options for connecting in the
|
39
|
+
# [Authentication
|
40
|
+
# Guide](https://googlecloudplatform.github.io/google-cloud-ruby/#/docs/guides/authentication).
|
36
41
|
#
|
37
42
|
# ```ruby
|
38
43
|
# require "google/cloud/pubsub"
|
@@ -507,7 +512,7 @@ module Google
|
|
507
512
|
# @param [Hash] client_config A hash of values to override the default
|
508
513
|
# behavior of the API client. Optional.
|
509
514
|
# @param [String] emulator_host Pub/Sub emulator host. Optional.
|
510
|
-
# If the param is nil,
|
515
|
+
# If the param is nil, uses the value of the `emulator_host` config.
|
511
516
|
# @param [String] project Alias for the `project_id` argument. Deprecated.
|
512
517
|
# @param [String] keyfile Alias for the `credentials` argument.
|
513
518
|
# Deprecated.
|
@@ -525,19 +530,24 @@ module Google
|
|
525
530
|
def self.new project_id: nil, credentials: nil, scope: nil, timeout: nil,
|
526
531
|
client_config: nil, emulator_host: nil, project: nil,
|
527
532
|
keyfile: nil
|
528
|
-
project_id ||= (project ||
|
533
|
+
project_id ||= (project || default_project_id)
|
529
534
|
project_id = project_id.to_s # Always cast to a string
|
530
|
-
|
535
|
+
raise ArgumentError, "project_id is missing" if project_id.empty?
|
531
536
|
|
532
|
-
|
537
|
+
scope ||= configure.scope
|
538
|
+
timeout ||= configure.timeout
|
539
|
+
client_config ||= configure.client_config
|
540
|
+
emulator_host ||= configure.emulator_host
|
533
541
|
if emulator_host
|
534
542
|
return Pubsub::Project.new(
|
535
543
|
Pubsub::Service.new(
|
536
544
|
project_id, :this_channel_is_insecure,
|
537
|
-
host: emulator_host
|
545
|
+
host: emulator_host
|
546
|
+
)
|
547
|
+
)
|
538
548
|
end
|
539
549
|
|
540
|
-
credentials ||= (keyfile ||
|
550
|
+
credentials ||= (keyfile || default_credentials(scope: scope))
|
541
551
|
unless credentials.is_a? Google::Auth::Credentials
|
542
552
|
credentials = Pubsub::Credentials.new credentials, scope: scope
|
543
553
|
end
|
@@ -545,7 +555,55 @@ module Google
|
|
545
555
|
Pubsub::Project.new(
|
546
556
|
Pubsub::Service.new(
|
547
557
|
project_id, credentials, timeout: timeout,
|
548
|
-
client_config: client_config
|
558
|
+
client_config: client_config
|
559
|
+
)
|
560
|
+
)
|
561
|
+
end
|
562
|
+
|
563
|
+
##
|
564
|
+
# Configure the Google Cloud Pubsub library.
|
565
|
+
#
|
566
|
+
# The following Pubsub configuration parameters are supported:
|
567
|
+
#
|
568
|
+
# * `project_id` - (String) Identifier for a Pubsub project. (The
|
569
|
+
# parameter `project` is considered deprecated, but may also be used.)
|
570
|
+
# * `credentials` - (String, Hash, Google::Auth::Credentials) The path to
|
571
|
+
# the keyfile as a String, the contents of the keyfile as a Hash, or a
|
572
|
+
# Google::Auth::Credentials object. (See {Pubsub::Credentials}) (The
|
573
|
+
# parameter `keyfile` is considered deprecated, but may also be used.)
|
574
|
+
# * `scope` - (String, Array<String>) The OAuth 2.0 scopes controlling
|
575
|
+
# the set of resources and operations that the connection can access.
|
576
|
+
# * `retries` - (Integer) Number of times to retry requests on server
|
577
|
+
# error.
|
578
|
+
# * `timeout` - (Integer) Default timeout to use in requests.
|
579
|
+
# * `client_config` - (Hash) A hash of values to override the default
|
580
|
+
# behavior of the API client.
|
581
|
+
# * `emulator_host` - (String) Host name of the emulator. Defaults to
|
582
|
+
# `ENV["PUBSUB_EMULATOR_HOST"]`
|
583
|
+
#
|
584
|
+
# @return [Google::Cloud::Config] The configuration object the
|
585
|
+
# Google::Cloud::Pubsub library uses.
|
586
|
+
#
|
587
|
+
def self.configure
|
588
|
+
yield Google::Cloud.configure.pubsub if block_given?
|
589
|
+
|
590
|
+
Google::Cloud.configure.pubsub
|
591
|
+
end
|
592
|
+
|
593
|
+
##
|
594
|
+
# @private Default project.
|
595
|
+
def self.default_project_id
|
596
|
+
Google::Cloud.configure.pubsub.project_id ||
|
597
|
+
Google::Cloud.configure.project_id ||
|
598
|
+
Google::Cloud.env.project_id
|
599
|
+
end
|
600
|
+
|
601
|
+
##
|
602
|
+
# @private Default credentials.
|
603
|
+
def self.default_credentials scope: nil
|
604
|
+
Google::Cloud.configure.pubsub.credentials ||
|
605
|
+
Google::Cloud.configure.credentials ||
|
606
|
+
Pubsub::Credentials.default(scope: scope)
|
549
607
|
end
|
550
608
|
end
|
551
609
|
end
|
@@ -93,7 +93,7 @@ module Google
|
|
93
93
|
msg = create_pubsub_message data, attributes
|
94
94
|
|
95
95
|
synchronize do
|
96
|
-
|
96
|
+
raise "Can't publish when stopped." if @stopped
|
97
97
|
|
98
98
|
if @batch.nil?
|
99
99
|
@batch ||= Batch.new self
|
@@ -238,7 +238,7 @@ module Google
|
|
238
238
|
publish_result = PublishResult.from_grpc(item.msg)
|
239
239
|
execute_callback_async item.callback, publish_result
|
240
240
|
end
|
241
|
-
rescue => e
|
241
|
+
rescue StandardError => e
|
242
242
|
batch.items.each do |item|
|
243
243
|
next unless item.callback
|
244
244
|
|
@@ -38,19 +38,19 @@ module Google
|
|
38
38
|
# pubsub.project_id #=> "my-project"
|
39
39
|
#
|
40
40
|
class Credentials < Google::Auth::Credentials
|
41
|
-
SCOPE = ["https://www.googleapis.com/auth/pubsub"]
|
42
|
-
PATH_ENV_VARS = %w
|
41
|
+
SCOPE = ["https://www.googleapis.com/auth/pubsub"].freeze
|
42
|
+
PATH_ENV_VARS = %w[PUBSUB_CREDENTIALS
|
43
43
|
PUBSUB_KEYFILE
|
44
44
|
GOOGLE_CLOUD_CREDENTIALS
|
45
45
|
GOOGLE_CLOUD_KEYFILE
|
46
|
-
GCLOUD_KEYFILE
|
47
|
-
JSON_ENV_VARS = %w
|
46
|
+
GCLOUD_KEYFILE].freeze
|
47
|
+
JSON_ENV_VARS = %w[PUBSUB_CREDENTIALS_JSON
|
48
48
|
PUBSUB_KEYFILE_JSON
|
49
49
|
GOOGLE_CLOUD_CREDENTIALS_JSON
|
50
50
|
GOOGLE_CLOUD_KEYFILE_JSON
|
51
|
-
GCLOUD_KEYFILE_JSON
|
51
|
+
GCLOUD_KEYFILE_JSON].freeze
|
52
52
|
DEFAULT_PATHS = \
|
53
|
-
["~/.config/gcloud/application_default_credentials.json"]
|
53
|
+
["~/.config/gcloud/application_default_credentials.json"].freeze
|
54
54
|
end
|
55
55
|
end
|
56
56
|
end
|
@@ -66,7 +66,8 @@ module Google
|
|
66
66
|
|
67
67
|
@grpc = Google::Pubsub::V1::PubsubMessage.new(
|
68
68
|
data: String(data).encode("ASCII-8BIT"),
|
69
|
-
attributes: attributes
|
69
|
+
attributes: attributes
|
70
|
+
)
|
70
71
|
end
|
71
72
|
|
72
73
|
##
|
@@ -90,14 +91,14 @@ module Google
|
|
90
91
|
def message_id
|
91
92
|
@grpc.message_id
|
92
93
|
end
|
93
|
-
|
94
|
+
alias msg_id message_id
|
94
95
|
|
95
96
|
##
|
96
97
|
# The time at which the message was published.
|
97
98
|
def published_at
|
98
99
|
Convert.timestamp_to_time @grpc.publish_time
|
99
100
|
end
|
100
|
-
|
101
|
+
alias publish_time published_at
|
101
102
|
|
102
103
|
##
|
103
104
|
# @private New Message from a Google::Pubsub::V1::PubsubMessage object.
|
@@ -14,7 +14,6 @@
|
|
14
14
|
|
15
15
|
|
16
16
|
require "google/cloud/errors"
|
17
|
-
require "google/cloud/env"
|
18
17
|
require "google/cloud/pubsub/service"
|
19
18
|
require "google/cloud/pubsub/credentials"
|
20
19
|
require "google/cloud/pubsub/topic"
|
@@ -71,16 +70,7 @@ module Google
|
|
71
70
|
def project_id
|
72
71
|
service.project
|
73
72
|
end
|
74
|
-
|
75
|
-
|
76
|
-
##
|
77
|
-
# @private Default project.
|
78
|
-
def self.default_project_id
|
79
|
-
ENV["PUBSUB_PROJECT"] ||
|
80
|
-
ENV["GOOGLE_CLOUD_PROJECT"] ||
|
81
|
-
ENV["GCLOUD_PROJECT"] ||
|
82
|
-
Google::Cloud.env.project_id
|
83
|
-
end
|
73
|
+
alias project project_id
|
84
74
|
|
85
75
|
##
|
86
76
|
# Retrieves topic by name.
|
@@ -166,8 +156,8 @@ module Google
|
|
166
156
|
rescue Google::Cloud::NotFoundError
|
167
157
|
nil
|
168
158
|
end
|
169
|
-
|
170
|
-
|
159
|
+
alias get_topic topic
|
160
|
+
alias find_topic topic
|
171
161
|
|
172
162
|
##
|
173
163
|
# Creates a new topic.
|
@@ -206,7 +196,7 @@ module Google
|
|
206
196
|
grpc = service.create_topic topic_name
|
207
197
|
Topic.from_grpc grpc, service, async: async
|
208
198
|
end
|
209
|
-
|
199
|
+
alias new_topic create_topic
|
210
200
|
|
211
201
|
##
|
212
202
|
# Retrieves a list of topics for the given project.
|
@@ -245,8 +235,8 @@ module Google
|
|
245
235
|
grpc = service.list_topics options
|
246
236
|
Topic::List.from_grpc grpc, service, max
|
247
237
|
end
|
248
|
-
|
249
|
-
|
238
|
+
alias find_topics topics
|
239
|
+
alias list_topics topics
|
250
240
|
|
251
241
|
##
|
252
242
|
# Retrieves subscription by name.
|
@@ -291,8 +281,8 @@ module Google
|
|
291
281
|
rescue Google::Cloud::NotFoundError
|
292
282
|
nil
|
293
283
|
end
|
294
|
-
|
295
|
-
|
284
|
+
alias get_subscription subscription
|
285
|
+
alias find_subscription subscription
|
296
286
|
|
297
287
|
##
|
298
288
|
# Retrieves a list of subscriptions for the given project.
|
@@ -330,8 +320,8 @@ module Google
|
|
330
320
|
grpc = service.list_subscriptions options
|
331
321
|
Subscription::List.from_grpc grpc, service, max
|
332
322
|
end
|
333
|
-
|
334
|
-
|
323
|
+
alias find_subscriptions subscriptions
|
324
|
+
alias list_subscriptions subscriptions
|
335
325
|
|
336
326
|
|
337
327
|
##
|
@@ -370,8 +360,8 @@ module Google
|
|
370
360
|
grpc = service.list_snapshots options
|
371
361
|
Snapshot::List.from_grpc grpc, service, max
|
372
362
|
end
|
373
|
-
|
374
|
-
|
363
|
+
alias find_snapshots snapshots
|
364
|
+
alias list_snapshots snapshots
|
375
365
|
|
376
366
|
protected
|
377
367
|
|
@@ -379,7 +369,7 @@ module Google
|
|
379
369
|
# @private Raise an error unless an active connection to the service is
|
380
370
|
# available.
|
381
371
|
def ensure_service!
|
382
|
-
|
372
|
+
raise "Must have active connection to service" unless service
|
383
373
|
end
|
384
374
|
|
385
375
|
##
|
@@ -32,7 +32,7 @@ module Google
|
|
32
32
|
def message
|
33
33
|
@message
|
34
34
|
end
|
35
|
-
|
35
|
+
alias msg message
|
36
36
|
|
37
37
|
##
|
38
38
|
# The message's data.
|
@@ -52,14 +52,14 @@ module Google
|
|
52
52
|
def message_id
|
53
53
|
message.message_id
|
54
54
|
end
|
55
|
-
|
55
|
+
alias msg_id message_id
|
56
56
|
|
57
57
|
##
|
58
58
|
# The time at which the message was published.
|
59
59
|
def published_at
|
60
60
|
message.published_at
|
61
61
|
end
|
62
|
-
|
62
|
+
alias publish_time published_at
|
63
63
|
|
64
64
|
##
|
65
65
|
# The error that was raised when published, if any.
|
@@ -68,7 +68,7 @@ module Google
|
|
68
68
|
def message
|
69
69
|
Message.from_grpc @grpc.message
|
70
70
|
end
|
71
|
-
|
71
|
+
alias msg message
|
72
72
|
|
73
73
|
##
|
74
74
|
# The received message payload. This data is a list of bytes encoded as
|
@@ -89,14 +89,14 @@ module Google
|
|
89
89
|
def message_id
|
90
90
|
message.message_id
|
91
91
|
end
|
92
|
-
|
92
|
+
alias msg_id message_id
|
93
93
|
|
94
94
|
##
|
95
95
|
# The time at which the message was published.
|
96
96
|
def published_at
|
97
97
|
message.published_at
|
98
98
|
end
|
99
|
-
|
99
|
+
alias publish_time published_at
|
100
100
|
|
101
101
|
##
|
102
102
|
# Acknowledges receipt of the message.
|
@@ -123,7 +123,7 @@ module Google
|
|
123
123
|
ensure_subscription!
|
124
124
|
subscription.acknowledge ack_id
|
125
125
|
end
|
126
|
-
|
126
|
+
alias ack! acknowledge!
|
127
127
|
|
128
128
|
##
|
129
129
|
# Modifies the acknowledge deadline for the message.
|
@@ -160,7 +160,7 @@ module Google
|
|
160
160
|
ensure_subscription!
|
161
161
|
subscription.delay new_deadline, ack_id
|
162
162
|
end
|
163
|
-
|
163
|
+
alias modify_ack_deadline! delay!
|
164
164
|
|
165
165
|
##
|
166
166
|
# Resets the acknowledge deadline for the message without acknowledging
|
@@ -190,8 +190,8 @@ module Google
|
|
190
190
|
def reject!
|
191
191
|
delay! 0
|
192
192
|
end
|
193
|
-
|
194
|
-
|
193
|
+
alias nack! reject!
|
194
|
+
alias ignore! reject!
|
195
195
|
|
196
196
|
##
|
197
197
|
# @private New ReceivedMessage from a
|
@@ -208,7 +208,7 @@ module Google
|
|
208
208
|
##
|
209
209
|
# Raise an error unless an active subscription is available.
|
210
210
|
def ensure_subscription!
|
211
|
-
|
211
|
+
raise "Must have active subscription" unless subscription
|
212
212
|
end
|
213
213
|
end
|
214
214
|
end
|
@@ -66,7 +66,8 @@ module Google
|
|
66
66
|
timeout: timeout,
|
67
67
|
client_config: client_config,
|
68
68
|
lib_name: "gccl",
|
69
|
-
lib_version: Google::Cloud::Pubsub::VERSION
|
69
|
+
lib_version: Google::Cloud::Pubsub::VERSION
|
70
|
+
)
|
70
71
|
end
|
71
72
|
end
|
72
73
|
attr_accessor :mocked_subscriber
|
@@ -78,7 +79,8 @@ module Google
|
|
78
79
|
credentials: channel,
|
79
80
|
timeout: timeout,
|
80
81
|
lib_name: "gccl",
|
81
|
-
lib_version: Google::Cloud::Pubsub::VERSION
|
82
|
+
lib_version: Google::Cloud::Pubsub::VERSION
|
83
|
+
)
|
82
84
|
end
|
83
85
|
end
|
84
86
|
attr_accessor :mocked_publisher
|
@@ -157,7 +157,7 @@ module Google
|
|
157
157
|
# @private Raise an error unless an active connection to the service is
|
158
158
|
# available.
|
159
159
|
def ensure_service!
|
160
|
-
|
160
|
+
raise "Must have active connection to service" unless service
|
161
161
|
end
|
162
162
|
end
|
163
163
|
end
|
@@ -163,7 +163,7 @@ module Google
|
|
163
163
|
# @private Raise an error unless an active connection to the service
|
164
164
|
# is available.
|
165
165
|
def ensure_service!
|
166
|
-
|
166
|
+
raise "Must have active connection to service" unless @service
|
167
167
|
end
|
168
168
|
|
169
169
|
def next_snapshots
|
@@ -87,7 +87,7 @@ module Google
|
|
87
87
|
@started = nil
|
88
88
|
@stopped = nil
|
89
89
|
|
90
|
-
stream_pool = @streams
|
90
|
+
stream_pool = Array.new(@streams) do
|
91
91
|
Thread.new { Stream.new self }
|
92
92
|
end
|
93
93
|
@stream_pool = stream_pool.map(&:value)
|
@@ -172,7 +172,8 @@ module Google
|
|
172
172
|
##
|
173
173
|
# @private
|
174
174
|
def to_s
|
175
|
-
format "(subscription:
|
175
|
+
format "(subscription: %<sub>s, streams: %<count>i)",
|
176
|
+
sub: subscription_name, count: streams
|
176
177
|
end
|
177
178
|
|
178
179
|
##
|
@@ -70,10 +70,12 @@ module Google
|
|
70
70
|
synchronize do
|
71
71
|
break if @stopped
|
72
72
|
|
73
|
-
@inventory.stop
|
74
73
|
@stopped = true
|
75
|
-
|
76
|
-
@
|
74
|
+
|
75
|
+
@inventory.stop
|
76
|
+
|
77
|
+
# signal to the background thread that we are unpaused
|
78
|
+
@pause_cond.broadcast
|
77
79
|
end
|
78
80
|
|
79
81
|
self
|
@@ -175,7 +177,8 @@ module Google
|
|
175
177
|
|
176
178
|
# @private
|
177
179
|
def to_s
|
178
|
-
format "(inventory:
|
180
|
+
format "(inventory: %<inv>i, status: %<sts>s)",
|
181
|
+
inv: inventory.count, sts: status
|
179
182
|
end
|
180
183
|
|
181
184
|
# @private
|
@@ -188,14 +191,17 @@ module Google
|
|
188
191
|
# rubocop:disable all
|
189
192
|
|
190
193
|
def background_run enum
|
191
|
-
|
194
|
+
loop do
|
192
195
|
synchronize do
|
193
|
-
if @paused
|
196
|
+
if @paused && !@stopped
|
194
197
|
@pause_cond.wait
|
195
198
|
next
|
196
199
|
end
|
197
200
|
end
|
198
201
|
|
202
|
+
# Break loop, close thread if stopped
|
203
|
+
break if synchronize { @stopped }
|
204
|
+
|
199
205
|
begin
|
200
206
|
# Cannot syncronize the enumerator, causes deadlock
|
201
207
|
response = enum.next
|
@@ -232,8 +238,8 @@ module Google
|
|
232
238
|
# Also stealthly restart the stream on Unavailable, Cancelled,
|
233
239
|
# ResourceExhausted, and Internal.
|
234
240
|
synchronize { start_streaming! }
|
235
|
-
rescue => e
|
236
|
-
|
241
|
+
rescue StandardError => e
|
242
|
+
raise Google::Cloud::Error.from_error(e)
|
237
243
|
end
|
238
244
|
|
239
245
|
# rubocop:enable all
|
@@ -245,6 +251,9 @@ module Google
|
|
245
251
|
end
|
246
252
|
|
247
253
|
def start_streaming!
|
254
|
+
# Don't allow a stream to restart if already stopped
|
255
|
+
return if @stopped
|
256
|
+
|
248
257
|
# signal to the previous queue to shut down
|
249
258
|
old_queue = []
|
250
259
|
old_queue = @request_queue.dump_queue if @request_queue
|
@@ -270,6 +279,7 @@ module Google
|
|
270
279
|
end
|
271
280
|
|
272
281
|
def pause_streaming?
|
282
|
+
return if @stopped
|
273
283
|
return if @paused
|
274
284
|
|
275
285
|
@inventory.full?
|
@@ -284,9 +294,10 @@ module Google
|
|
284
294
|
end
|
285
295
|
|
286
296
|
def unpause_streaming?
|
297
|
+
return if @stopped
|
287
298
|
return if @paused.nil?
|
288
299
|
|
289
|
-
@inventory.count < @inventory.limit*0.8
|
300
|
+
@inventory.count < @inventory.limit * 0.8
|
290
301
|
end
|
291
302
|
|
292
303
|
def initial_input_request
|
@@ -341,7 +352,9 @@ module Google
|
|
341
352
|
ack_ids = Array(ack_ids).flatten
|
342
353
|
synchronize do
|
343
354
|
@_ack_ids += ack_ids
|
344
|
-
@
|
355
|
+
unless @stopped
|
356
|
+
@background_thread ||= Thread.new { background_run }
|
357
|
+
end
|
345
358
|
end
|
346
359
|
end
|
347
360
|
|
@@ -103,7 +103,6 @@ module Google
|
|
103
103
|
@grpc = service.update_subscription update_grpc,
|
104
104
|
:ack_deadline_seconds
|
105
105
|
@lazy = nil
|
106
|
-
self
|
107
106
|
end
|
108
107
|
|
109
108
|
##
|
@@ -126,7 +125,6 @@ module Google
|
|
126
125
|
@grpc = service.update_subscription update_grpc,
|
127
126
|
:retain_acked_messages
|
128
127
|
@lazy = nil
|
129
|
-
self
|
130
128
|
end
|
131
129
|
|
132
130
|
##
|
@@ -152,7 +150,6 @@ module Google
|
|
152
150
|
@grpc = service.update_subscription update_grpc,
|
153
151
|
:message_retention_duration
|
154
152
|
@lazy = nil
|
155
|
-
self
|
156
153
|
end
|
157
154
|
|
158
155
|
##
|
@@ -168,10 +165,13 @@ module Google
|
|
168
165
|
def endpoint= new_endpoint
|
169
166
|
ensure_service!
|
170
167
|
service.modify_push_config name, new_endpoint, {}
|
168
|
+
|
169
|
+
return unless @grpc
|
170
|
+
|
171
171
|
@grpc.push_config = Google::Pubsub::V1::PushConfig.new(
|
172
172
|
push_endpoint: new_endpoint,
|
173
173
|
attributes: {}
|
174
|
-
)
|
174
|
+
)
|
175
175
|
end
|
176
176
|
|
177
177
|
##
|
@@ -429,7 +429,7 @@ module Google
|
|
429
429
|
service.acknowledge name, *ack_ids
|
430
430
|
true
|
431
431
|
end
|
432
|
-
|
432
|
+
alias ack acknowledge
|
433
433
|
|
434
434
|
##
|
435
435
|
# Modifies the acknowledge deadline for messages.
|
@@ -463,7 +463,7 @@ module Google
|
|
463
463
|
service.modify_ack_deadline name, ack_ids, new_deadline
|
464
464
|
true
|
465
465
|
end
|
466
|
-
|
466
|
+
alias modify_ack_deadline delay
|
467
467
|
|
468
468
|
##
|
469
469
|
# Creates a new {Snapshot} from the subscription. The created snapshot
|
@@ -510,7 +510,7 @@ module Google
|
|
510
510
|
grpc = service.create_snapshot name, snapshot_name
|
511
511
|
Snapshot.from_grpc grpc, service
|
512
512
|
end
|
513
|
-
|
513
|
+
alias new_snapshot create_snapshot
|
514
514
|
|
515
515
|
##
|
516
516
|
# Resets the subscription's backlog to a given {Snapshot} or to a point
|
@@ -604,7 +604,7 @@ module Google
|
|
604
604
|
policy = Policy.from_grpc grpc
|
605
605
|
return policy unless block_given?
|
606
606
|
yield policy
|
607
|
-
|
607
|
+
update_policy policy
|
608
608
|
end
|
609
609
|
|
610
610
|
##
|
@@ -634,13 +634,14 @@ module Google
|
|
634
634
|
#
|
635
635
|
# policy.add "roles/owner", "user:owner@example.com"
|
636
636
|
#
|
637
|
-
# sub.
|
637
|
+
# sub.update_policy policy # API call
|
638
638
|
#
|
639
|
-
def
|
639
|
+
def update_policy new_policy
|
640
640
|
ensure_service!
|
641
641
|
grpc = service.set_subscription_policy name, new_policy.to_grpc
|
642
642
|
Policy.from_grpc grpc
|
643
643
|
end
|
644
|
+
alias policy= update_policy
|
644
645
|
|
645
646
|
##
|
646
647
|
# Tests the specified permissions against the [Cloud
|
@@ -707,7 +708,7 @@ module Google
|
|
707
708
|
# @private Raise an error unless an active connection to the service is
|
708
709
|
# available.
|
709
710
|
def ensure_service!
|
710
|
-
|
711
|
+
raise "Must have active connection to service" unless service
|
711
712
|
end
|
712
713
|
|
713
714
|
##
|
@@ -184,7 +184,7 @@ module Google
|
|
184
184
|
# @private Raise an error unless an active connection to the service
|
185
185
|
# is available.
|
186
186
|
def ensure_service!
|
187
|
-
|
187
|
+
raise "Must have active connection to service" unless @service
|
188
188
|
end
|
189
189
|
|
190
190
|
def next_subscriptions
|
@@ -161,8 +161,8 @@ module Google
|
|
161
161
|
grpc = service.create_subscription name, subscription_name, options
|
162
162
|
Subscription.from_grpc grpc, service
|
163
163
|
end
|
164
|
-
|
165
|
-
|
164
|
+
alias create_subscription subscribe
|
165
|
+
alias new_subscription subscribe
|
166
166
|
|
167
167
|
##
|
168
168
|
# Retrieves subscription by name.
|
@@ -205,8 +205,8 @@ module Google
|
|
205
205
|
rescue Google::Cloud::NotFoundError
|
206
206
|
nil
|
207
207
|
end
|
208
|
-
|
209
|
-
|
208
|
+
alias get_subscription subscription
|
209
|
+
alias find_subscription subscription
|
210
210
|
|
211
211
|
##
|
212
212
|
# Retrieves a list of subscription names for the given project.
|
@@ -246,8 +246,8 @@ module Google
|
|
246
246
|
grpc = service.list_topics_subscriptions name, options
|
247
247
|
Subscription::List.from_topic_grpc grpc, service, name, max
|
248
248
|
end
|
249
|
-
|
250
|
-
|
249
|
+
alias find_subscriptions subscriptions
|
250
|
+
alias list_subscriptions subscriptions
|
251
251
|
|
252
252
|
##
|
253
253
|
# Publishes one or more messages to the topic.
|
@@ -412,7 +412,7 @@ module Google
|
|
412
412
|
policy = Policy.from_grpc grpc
|
413
413
|
return policy unless block_given?
|
414
414
|
yield policy
|
415
|
-
|
415
|
+
update_policy policy
|
416
416
|
end
|
417
417
|
|
418
418
|
##
|
@@ -442,13 +442,14 @@ module Google
|
|
442
442
|
#
|
443
443
|
# policy.add "roles/owner", "user:owner@example.com"
|
444
444
|
#
|
445
|
-
# topic.
|
445
|
+
# topic.update_policy policy # API call
|
446
446
|
#
|
447
|
-
def
|
447
|
+
def update_policy new_policy
|
448
448
|
ensure_service!
|
449
449
|
grpc = service.set_topic_policy name, new_policy.to_grpc
|
450
450
|
@policy = Policy.from_grpc grpc
|
451
451
|
end
|
452
|
+
alias policy= update_policy
|
452
453
|
|
453
454
|
##
|
454
455
|
# Tests the specified permissions against the [Cloud
|
@@ -555,7 +556,7 @@ module Google
|
|
555
556
|
# @private Raise an error unless an active connection to the service is
|
556
557
|
# available.
|
557
558
|
def ensure_service!
|
558
|
-
|
559
|
+
raise "Must have active connection to service" unless service
|
559
560
|
end
|
560
561
|
|
561
562
|
##
|
@@ -162,7 +162,7 @@ module Google
|
|
162
162
|
# @private Raise an error unless an active connection to the service
|
163
163
|
# is available.
|
164
164
|
def ensure_service!
|
165
|
-
|
165
|
+
raise "Must have active connection to service" unless @service
|
166
166
|
end
|
167
167
|
end
|
168
168
|
end
|
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.
|
4
|
+
version: 0.30.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:
|
12
|
+
date: 2018-02-28 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: google-cloud-core
|
@@ -17,14 +17,14 @@ dependencies:
|
|
17
17
|
requirements:
|
18
18
|
- - "~>"
|
19
19
|
- !ruby/object:Gem::Version
|
20
|
-
version: '1.
|
20
|
+
version: '1.2'
|
21
21
|
type: :runtime
|
22
22
|
prerelease: false
|
23
23
|
version_requirements: !ruby/object:Gem::Requirement
|
24
24
|
requirements:
|
25
25
|
- - "~>"
|
26
26
|
- !ruby/object:Gem::Version
|
27
|
-
version: '1.
|
27
|
+
version: '1.2'
|
28
28
|
- !ruby/object:Gem::Dependency
|
29
29
|
name: google-gax
|
30
30
|
requirement: !ruby/object:Gem::Requirement
|
@@ -141,16 +141,16 @@ dependencies:
|
|
141
141
|
name: rubocop
|
142
142
|
requirement: !ruby/object:Gem::Requirement
|
143
143
|
requirements:
|
144
|
-
- - "
|
144
|
+
- - "~>"
|
145
145
|
- !ruby/object:Gem::Version
|
146
|
-
version: 0.
|
146
|
+
version: 0.50.0
|
147
147
|
type: :development
|
148
148
|
prerelease: false
|
149
149
|
version_requirements: !ruby/object:Gem::Requirement
|
150
150
|
requirements:
|
151
|
-
- - "
|
151
|
+
- - "~>"
|
152
152
|
- !ruby/object:Gem::Version
|
153
|
-
version: 0.
|
153
|
+
version: 0.50.0
|
154
154
|
- !ruby/object:Gem::Dependency
|
155
155
|
name: simplecov
|
156
156
|
requirement: !ruby/object:Gem::Requirement
|
@@ -259,7 +259,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
259
259
|
version: '0'
|
260
260
|
requirements: []
|
261
261
|
rubyforge_project:
|
262
|
-
rubygems_version: 2.7.
|
262
|
+
rubygems_version: 2.7.6
|
263
263
|
signing_key:
|
264
264
|
specification_version: 4
|
265
265
|
summary: API Client library for Google Cloud Pub/Sub
|