google-cloud-pubsub 0.33.2 → 0.34.0
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 +4 -4
- data/AUTHENTICATION.md +4 -4
- data/CHANGELOG.md +45 -0
- data/EMULATOR.md +2 -2
- data/OVERVIEW.md +81 -43
- data/lib/google-cloud-pubsub.rb +10 -7
- data/lib/google/cloud/pubsub.rb +38 -21
- data/lib/google/cloud/pubsub/async_publisher.rb +8 -6
- data/lib/google/cloud/pubsub/batch_publisher.rb +7 -5
- data/lib/google/cloud/pubsub/convert.rb +5 -3
- data/lib/google/cloud/pubsub/credentials.rb +6 -4
- data/lib/google/cloud/pubsub/message.rb +9 -6
- data/lib/google/cloud/pubsub/policy.rb +12 -10
- data/lib/google/cloud/pubsub/project.rb +30 -28
- data/lib/google/cloud/pubsub/publish_result.rb +3 -1
- data/lib/google/cloud/pubsub/received_message.rb +11 -10
- data/lib/google/cloud/pubsub/service.rb +47 -37
- data/lib/google/cloud/pubsub/snapshot.rb +11 -9
- data/lib/google/cloud/pubsub/snapshot/list.rb +10 -8
- data/lib/google/cloud/pubsub/subscriber.rb +32 -6
- data/lib/google/cloud/pubsub/subscriber/enumerator_queue.rb +3 -1
- data/lib/google/cloud/pubsub/subscriber/inventory.rb +4 -2
- data/lib/google/cloud/pubsub/subscriber/stream.rb +23 -43
- data/lib/google/cloud/pubsub/subscriber/timed_unary_buffer.rb +221 -0
- data/lib/google/cloud/pubsub/subscription.rb +157 -80
- data/lib/google/cloud/pubsub/subscription/list.rb +12 -10
- data/lib/google/cloud/pubsub/topic.rb +79 -51
- data/lib/google/cloud/pubsub/topic/list.rb +10 -8
- data/lib/google/cloud/pubsub/v1/credentials.rb +4 -2
- data/lib/google/cloud/pubsub/v1/doc/google/iam/v1/iam_policy.rb +1 -43
- data/lib/google/cloud/pubsub/v1/doc/google/iam/v1/policy.rb +1 -108
- data/lib/google/cloud/pubsub/v1/doc/google/protobuf/duration.rb +1 -1
- data/lib/google/cloud/pubsub/v1/doc/google/protobuf/empty.rb +1 -1
- data/lib/google/cloud/pubsub/v1/doc/google/protobuf/field_mask.rb +1 -1
- data/lib/google/cloud/pubsub/v1/doc/google/protobuf/timestamp.rb +1 -1
- data/lib/google/cloud/pubsub/v1/doc/google/pubsub/v1/pubsub.rb +107 -61
- data/lib/google/cloud/pubsub/v1/publisher_client.rb +58 -55
- data/lib/google/cloud/pubsub/v1/publisher_client_config.json +0 -4
- data/lib/google/cloud/pubsub/v1/subscriber_client.rb +177 -128
- data/lib/google/cloud/pubsub/v1/subscriber_client_config.json +0 -4
- data/lib/google/cloud/pubsub/version.rb +4 -2
- data/lib/google/pubsub/v1/pubsub_pb.rb +48 -40
- data/lib/google/pubsub/v1/pubsub_services_pb.rb +201 -161
- metadata +6 -7
- data/lib/google/cloud/pubsub/subscriber/async_stream_pusher.rb +0 -223
- data/lib/google/cloud/pubsub/subscriber/async_unary_pusher.rb +0 -271
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.34.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: 2019-02-04 00:00:00.000000000 Z
|
|
13
13
|
dependencies:
|
|
14
14
|
- !ruby/object:Gem::Dependency
|
|
15
15
|
name: google-cloud-core
|
|
@@ -157,14 +157,14 @@ dependencies:
|
|
|
157
157
|
requirements:
|
|
158
158
|
- - "~>"
|
|
159
159
|
- !ruby/object:Gem::Version
|
|
160
|
-
version: 0.
|
|
160
|
+
version: 0.61.0
|
|
161
161
|
type: :development
|
|
162
162
|
prerelease: false
|
|
163
163
|
version_requirements: !ruby/object:Gem::Requirement
|
|
164
164
|
requirements:
|
|
165
165
|
- - "~>"
|
|
166
166
|
- !ruby/object:Gem::Version
|
|
167
|
-
version: 0.
|
|
167
|
+
version: 0.61.0
|
|
168
168
|
- !ruby/object:Gem::Dependency
|
|
169
169
|
name: simplecov
|
|
170
170
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -240,11 +240,10 @@ files:
|
|
|
240
240
|
- lib/google/cloud/pubsub/snapshot.rb
|
|
241
241
|
- lib/google/cloud/pubsub/snapshot/list.rb
|
|
242
242
|
- lib/google/cloud/pubsub/subscriber.rb
|
|
243
|
-
- lib/google/cloud/pubsub/subscriber/async_stream_pusher.rb
|
|
244
|
-
- lib/google/cloud/pubsub/subscriber/async_unary_pusher.rb
|
|
245
243
|
- lib/google/cloud/pubsub/subscriber/enumerator_queue.rb
|
|
246
244
|
- lib/google/cloud/pubsub/subscriber/inventory.rb
|
|
247
245
|
- lib/google/cloud/pubsub/subscriber/stream.rb
|
|
246
|
+
- lib/google/cloud/pubsub/subscriber/timed_unary_buffer.rb
|
|
248
247
|
- lib/google/cloud/pubsub/subscription.rb
|
|
249
248
|
- lib/google/cloud/pubsub/subscription/list.rb
|
|
250
249
|
- lib/google/cloud/pubsub/topic.rb
|
|
@@ -285,7 +284,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
285
284
|
version: '0'
|
|
286
285
|
requirements: []
|
|
287
286
|
rubyforge_project:
|
|
288
|
-
rubygems_version: 2.7.
|
|
287
|
+
rubygems_version: 2.7.6
|
|
289
288
|
signing_key:
|
|
290
289
|
specification_version: 4
|
|
291
290
|
summary: API Client library for Google Cloud Pub/Sub
|
|
@@ -1,223 +0,0 @@
|
|
|
1
|
-
# Copyright 2017 Google LLC
|
|
2
|
-
#
|
|
3
|
-
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
-
# you may not use this file except in compliance with the License.
|
|
5
|
-
# You may obtain a copy of the License at
|
|
6
|
-
#
|
|
7
|
-
# https://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
-
#
|
|
9
|
-
# Unless required by applicable law or agreed to in writing, software
|
|
10
|
-
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
-
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
-
# See the License for the specific language governing permissions and
|
|
13
|
-
# limitations under the License.
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
require "monitor"
|
|
17
|
-
require "concurrent"
|
|
18
|
-
|
|
19
|
-
module Google
|
|
20
|
-
module Cloud
|
|
21
|
-
module Pubsub
|
|
22
|
-
class Subscriber
|
|
23
|
-
##
|
|
24
|
-
# @private
|
|
25
|
-
# # AsyncStreamPusher
|
|
26
|
-
#
|
|
27
|
-
class AsyncStreamPusher
|
|
28
|
-
include MonitorMixin
|
|
29
|
-
|
|
30
|
-
attr_reader :batch
|
|
31
|
-
attr_reader :max_bytes, :interval
|
|
32
|
-
|
|
33
|
-
def initialize stream, max_bytes: 10000000, interval: 1.0
|
|
34
|
-
@stream = stream
|
|
35
|
-
|
|
36
|
-
@max_bytes = max_bytes
|
|
37
|
-
@interval = interval
|
|
38
|
-
|
|
39
|
-
@cond = new_cond
|
|
40
|
-
|
|
41
|
-
# init MonitorMixin
|
|
42
|
-
super()
|
|
43
|
-
end
|
|
44
|
-
|
|
45
|
-
def acknowledge ack_ids
|
|
46
|
-
return true if ack_ids.empty?
|
|
47
|
-
|
|
48
|
-
synchronize do
|
|
49
|
-
ack_ids.each do |ack_id|
|
|
50
|
-
if @batch.nil?
|
|
51
|
-
@batch = Batch.new max_bytes: @max_bytes
|
|
52
|
-
@batch.ack ack_id
|
|
53
|
-
else
|
|
54
|
-
unless @batch.try_ack ack_id
|
|
55
|
-
push_batch_request!
|
|
56
|
-
|
|
57
|
-
@batch = Batch.new max_bytes: @max_bytes
|
|
58
|
-
@batch.ack ack_id
|
|
59
|
-
end
|
|
60
|
-
end
|
|
61
|
-
|
|
62
|
-
push_batch_request! if @batch.ready?
|
|
63
|
-
end
|
|
64
|
-
|
|
65
|
-
@cond.signal
|
|
66
|
-
end
|
|
67
|
-
|
|
68
|
-
nil
|
|
69
|
-
end
|
|
70
|
-
|
|
71
|
-
def modify_ack_deadline deadline, ack_ids
|
|
72
|
-
return true if ack_ids.empty?
|
|
73
|
-
|
|
74
|
-
synchronize do
|
|
75
|
-
ack_ids.each do |ack_id|
|
|
76
|
-
if @batch.nil?
|
|
77
|
-
@batch = Batch.new max_bytes: @max_bytes
|
|
78
|
-
@batch.delay deadline, ack_id
|
|
79
|
-
else
|
|
80
|
-
unless @batch.try_delay deadline, ack_id
|
|
81
|
-
push_batch_request!
|
|
82
|
-
|
|
83
|
-
@batch = Batch.new max_bytes: @max_bytes
|
|
84
|
-
@batch.delay deadline, ack_id
|
|
85
|
-
end
|
|
86
|
-
end
|
|
87
|
-
|
|
88
|
-
push_batch_request! if @batch.ready?
|
|
89
|
-
end
|
|
90
|
-
|
|
91
|
-
@cond.signal
|
|
92
|
-
end
|
|
93
|
-
|
|
94
|
-
nil
|
|
95
|
-
end
|
|
96
|
-
alias delay modify_ack_deadline
|
|
97
|
-
|
|
98
|
-
def start
|
|
99
|
-
synchronize do
|
|
100
|
-
@stopped = false
|
|
101
|
-
|
|
102
|
-
@background_thread ||= Thread.new { run_background }
|
|
103
|
-
end
|
|
104
|
-
|
|
105
|
-
self
|
|
106
|
-
end
|
|
107
|
-
|
|
108
|
-
def stop
|
|
109
|
-
synchronize do
|
|
110
|
-
push_batch_request!
|
|
111
|
-
|
|
112
|
-
@stopped = true
|
|
113
|
-
@cond.broadcast
|
|
114
|
-
end
|
|
115
|
-
|
|
116
|
-
self
|
|
117
|
-
end
|
|
118
|
-
|
|
119
|
-
def started?
|
|
120
|
-
!stopped?
|
|
121
|
-
end
|
|
122
|
-
|
|
123
|
-
def stopped?
|
|
124
|
-
synchronize { @stopped }
|
|
125
|
-
end
|
|
126
|
-
|
|
127
|
-
protected
|
|
128
|
-
|
|
129
|
-
def run_background
|
|
130
|
-
synchronize do
|
|
131
|
-
until @stopped
|
|
132
|
-
if @batch.nil?
|
|
133
|
-
@cond.wait # wait until broadcast
|
|
134
|
-
next
|
|
135
|
-
end
|
|
136
|
-
|
|
137
|
-
time_from_batch_creation = Time.now - @batch.created_at
|
|
138
|
-
time_until_next_push = @interval - time_from_batch_creation
|
|
139
|
-
|
|
140
|
-
if time_until_next_push <= 0
|
|
141
|
-
# interval met, publish the batch...
|
|
142
|
-
push_batch_request!
|
|
143
|
-
time_until_next_push = nil # wait until broadcast
|
|
144
|
-
end
|
|
145
|
-
|
|
146
|
-
@cond.wait time_until_next_push
|
|
147
|
-
end
|
|
148
|
-
end
|
|
149
|
-
end
|
|
150
|
-
|
|
151
|
-
def push_batch_request!
|
|
152
|
-
return unless @batch
|
|
153
|
-
|
|
154
|
-
@stream.push @batch.request
|
|
155
|
-
|
|
156
|
-
@batch = nil
|
|
157
|
-
end
|
|
158
|
-
|
|
159
|
-
class Batch
|
|
160
|
-
attr_reader :max_bytes, :request, :created_at
|
|
161
|
-
|
|
162
|
-
def initialize max_bytes: 10000000
|
|
163
|
-
@max_bytes = max_bytes
|
|
164
|
-
@request = Google::Pubsub::V1::StreamingPullRequest.new
|
|
165
|
-
@total_message_bytes = 0
|
|
166
|
-
@created_at = Time.now
|
|
167
|
-
end
|
|
168
|
-
|
|
169
|
-
def ack ack_id
|
|
170
|
-
@request.ack_ids << ack_id
|
|
171
|
-
@total_message_bytes += addl_ack_bytes ack_id
|
|
172
|
-
end
|
|
173
|
-
|
|
174
|
-
def try_ack ack_id
|
|
175
|
-
addl_bytes = addl_ack_bytes ack_id
|
|
176
|
-
return false if total_message_bytes + addl_bytes >= @max_bytes
|
|
177
|
-
|
|
178
|
-
ack ack_id
|
|
179
|
-
true
|
|
180
|
-
end
|
|
181
|
-
|
|
182
|
-
def addl_ack_bytes ack_id
|
|
183
|
-
ack_id.bytesize + 2
|
|
184
|
-
end
|
|
185
|
-
|
|
186
|
-
def delay deadline, ack_id
|
|
187
|
-
@request.modify_deadline_seconds << deadline
|
|
188
|
-
@request.modify_deadline_ack_ids << ack_id
|
|
189
|
-
@total_message_bytes += addl_delay_bytes deadline, ack_id
|
|
190
|
-
end
|
|
191
|
-
|
|
192
|
-
def try_delay deadline, ack_id
|
|
193
|
-
addl_bytes = addl_delay_bytes deadline, ack_id
|
|
194
|
-
return false if total_message_bytes + addl_bytes >= @max_bytes
|
|
195
|
-
|
|
196
|
-
delay deadline, ack_id
|
|
197
|
-
true
|
|
198
|
-
end
|
|
199
|
-
|
|
200
|
-
def addl_delay_bytes deadline, ack_id
|
|
201
|
-
bytes_for_int(deadline) + ack_id.bytesize + 4
|
|
202
|
-
end
|
|
203
|
-
|
|
204
|
-
def bytes_for_int num
|
|
205
|
-
# Ruby 2.0 does not have Integer#bit_length
|
|
206
|
-
return [num].pack("s").bytesize unless num.respond_to? :bit_length
|
|
207
|
-
|
|
208
|
-
(num.bit_length / 8.0).ceil
|
|
209
|
-
end
|
|
210
|
-
|
|
211
|
-
def ready?
|
|
212
|
-
total_message_bytes >= @max_bytes
|
|
213
|
-
end
|
|
214
|
-
|
|
215
|
-
def total_message_bytes
|
|
216
|
-
@total_message_bytes
|
|
217
|
-
end
|
|
218
|
-
end
|
|
219
|
-
end
|
|
220
|
-
end
|
|
221
|
-
end
|
|
222
|
-
end
|
|
223
|
-
end
|
|
@@ -1,271 +0,0 @@
|
|
|
1
|
-
# Copyright 2018 Google LLC
|
|
2
|
-
#
|
|
3
|
-
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
-
# you may not use this file except in compliance with the License.
|
|
5
|
-
# You may obtain a copy of the License at
|
|
6
|
-
#
|
|
7
|
-
# https://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
-
#
|
|
9
|
-
# Unless required by applicable law or agreed to in writing, software
|
|
10
|
-
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
-
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
-
# See the License for the specific language governing permissions and
|
|
13
|
-
# limitations under the License.
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
require "monitor"
|
|
17
|
-
require "concurrent"
|
|
18
|
-
|
|
19
|
-
module Google
|
|
20
|
-
module Cloud
|
|
21
|
-
module Pubsub
|
|
22
|
-
class Subscriber
|
|
23
|
-
##
|
|
24
|
-
# @private
|
|
25
|
-
# # AsyncUnaryPusher
|
|
26
|
-
#
|
|
27
|
-
class AsyncUnaryPusher
|
|
28
|
-
include MonitorMixin
|
|
29
|
-
|
|
30
|
-
attr_reader :batch
|
|
31
|
-
attr_reader :max_bytes, :interval
|
|
32
|
-
|
|
33
|
-
def initialize stream, max_bytes: 10000000, interval: 1.0
|
|
34
|
-
@stream = stream
|
|
35
|
-
|
|
36
|
-
@max_bytes = max_bytes
|
|
37
|
-
@interval = interval
|
|
38
|
-
|
|
39
|
-
@cond = new_cond
|
|
40
|
-
|
|
41
|
-
# init MonitorMixin
|
|
42
|
-
super()
|
|
43
|
-
end
|
|
44
|
-
|
|
45
|
-
def acknowledge ack_ids
|
|
46
|
-
return true if ack_ids.empty?
|
|
47
|
-
|
|
48
|
-
synchronize do
|
|
49
|
-
ack_ids.each do |ack_id|
|
|
50
|
-
if @batch.nil?
|
|
51
|
-
@batch = Batch.new max_bytes: @max_bytes
|
|
52
|
-
@batch.ack ack_id
|
|
53
|
-
else
|
|
54
|
-
unless @batch.try_ack ack_id
|
|
55
|
-
push_batch_request!
|
|
56
|
-
|
|
57
|
-
@batch = Batch.new max_bytes: @max_bytes
|
|
58
|
-
@batch.ack ack_id
|
|
59
|
-
end
|
|
60
|
-
end
|
|
61
|
-
|
|
62
|
-
push_batch_request! if @batch.ready?
|
|
63
|
-
end
|
|
64
|
-
|
|
65
|
-
@cond.signal
|
|
66
|
-
end
|
|
67
|
-
|
|
68
|
-
nil
|
|
69
|
-
end
|
|
70
|
-
|
|
71
|
-
def modify_ack_deadline deadline, ack_ids
|
|
72
|
-
return true if ack_ids.empty?
|
|
73
|
-
|
|
74
|
-
synchronize do
|
|
75
|
-
ack_ids.each do |ack_id|
|
|
76
|
-
if @batch.nil?
|
|
77
|
-
@batch = Batch.new max_bytes: @max_bytes
|
|
78
|
-
@batch.delay deadline, ack_id
|
|
79
|
-
else
|
|
80
|
-
unless @batch.try_delay deadline, ack_id
|
|
81
|
-
push_batch_request!
|
|
82
|
-
|
|
83
|
-
@batch = Batch.new max_bytes: @max_bytes
|
|
84
|
-
@batch.delay deadline, ack_id
|
|
85
|
-
end
|
|
86
|
-
end
|
|
87
|
-
|
|
88
|
-
push_batch_request! if @batch.ready?
|
|
89
|
-
end
|
|
90
|
-
|
|
91
|
-
@cond.signal
|
|
92
|
-
end
|
|
93
|
-
|
|
94
|
-
nil
|
|
95
|
-
end
|
|
96
|
-
alias delay modify_ack_deadline
|
|
97
|
-
|
|
98
|
-
def start
|
|
99
|
-
synchronize do
|
|
100
|
-
@stopped = false
|
|
101
|
-
|
|
102
|
-
@background_thread ||= Thread.new { run_background }
|
|
103
|
-
end
|
|
104
|
-
|
|
105
|
-
self
|
|
106
|
-
end
|
|
107
|
-
|
|
108
|
-
def stop
|
|
109
|
-
synchronize do
|
|
110
|
-
push_batch_request!
|
|
111
|
-
|
|
112
|
-
@stopped = true
|
|
113
|
-
@cond.broadcast
|
|
114
|
-
end
|
|
115
|
-
|
|
116
|
-
self
|
|
117
|
-
end
|
|
118
|
-
|
|
119
|
-
def started?
|
|
120
|
-
!stopped?
|
|
121
|
-
end
|
|
122
|
-
|
|
123
|
-
def stopped?
|
|
124
|
-
synchronize { @stopped }
|
|
125
|
-
end
|
|
126
|
-
|
|
127
|
-
protected
|
|
128
|
-
|
|
129
|
-
def run_background
|
|
130
|
-
synchronize do
|
|
131
|
-
until @stopped
|
|
132
|
-
if @batch.nil?
|
|
133
|
-
@cond.wait # wait until broadcast
|
|
134
|
-
next
|
|
135
|
-
end
|
|
136
|
-
|
|
137
|
-
time_from_batch_creation = Time.now - @batch.created_at
|
|
138
|
-
time_until_next_push = @interval - time_from_batch_creation
|
|
139
|
-
|
|
140
|
-
if time_until_next_push <= 0
|
|
141
|
-
# interval met, publish the batch...
|
|
142
|
-
push_batch_request!
|
|
143
|
-
time_until_next_push = nil # wait until broadcast
|
|
144
|
-
end
|
|
145
|
-
|
|
146
|
-
@cond.wait time_until_next_push
|
|
147
|
-
end
|
|
148
|
-
end
|
|
149
|
-
end
|
|
150
|
-
|
|
151
|
-
def push_batch_request!
|
|
152
|
-
return unless @batch
|
|
153
|
-
|
|
154
|
-
sub_name = @stream.subscriber.subscription_name
|
|
155
|
-
service = @stream.subscriber.service
|
|
156
|
-
|
|
157
|
-
if @batch.ack?
|
|
158
|
-
ack_ids = @batch.ack_ids
|
|
159
|
-
push_change_request do
|
|
160
|
-
service.acknowledge sub_name, *ack_ids
|
|
161
|
-
end
|
|
162
|
-
end
|
|
163
|
-
if @batch.delay?
|
|
164
|
-
@batch.modify_deadline_hash.each do |delay_seconds, delay_ack_ids|
|
|
165
|
-
push_change_request do
|
|
166
|
-
service.modify_ack_deadline sub_name,
|
|
167
|
-
delay_ack_ids,
|
|
168
|
-
delay_seconds
|
|
169
|
-
end
|
|
170
|
-
end
|
|
171
|
-
end
|
|
172
|
-
|
|
173
|
-
@batch = nil
|
|
174
|
-
end
|
|
175
|
-
|
|
176
|
-
def push_change_request
|
|
177
|
-
return unless @stream.push_thread_pool.running?
|
|
178
|
-
|
|
179
|
-
Concurrent::Future.new(executor: @stream.push_thread_pool) do
|
|
180
|
-
begin
|
|
181
|
-
yield
|
|
182
|
-
rescue StandardError => push_error
|
|
183
|
-
@stream.subscriber.error! push_error
|
|
184
|
-
end
|
|
185
|
-
end.execute
|
|
186
|
-
end
|
|
187
|
-
|
|
188
|
-
class Batch
|
|
189
|
-
attr_reader :max_bytes, :request, :created_at
|
|
190
|
-
|
|
191
|
-
def initialize max_bytes: 10000000
|
|
192
|
-
@max_bytes = max_bytes
|
|
193
|
-
@request = Google::Pubsub::V1::StreamingPullRequest.new
|
|
194
|
-
@total_message_bytes = 0
|
|
195
|
-
@created_at = Time.now
|
|
196
|
-
end
|
|
197
|
-
|
|
198
|
-
def ack ack_id
|
|
199
|
-
@request.ack_ids << ack_id
|
|
200
|
-
@total_message_bytes += addl_ack_bytes ack_id
|
|
201
|
-
end
|
|
202
|
-
|
|
203
|
-
def try_ack ack_id
|
|
204
|
-
addl_bytes = addl_ack_bytes ack_id
|
|
205
|
-
return false if total_message_bytes + addl_bytes >= @max_bytes
|
|
206
|
-
|
|
207
|
-
ack ack_id
|
|
208
|
-
true
|
|
209
|
-
end
|
|
210
|
-
|
|
211
|
-
def addl_ack_bytes ack_id
|
|
212
|
-
ack_id.bytesize + 2
|
|
213
|
-
end
|
|
214
|
-
|
|
215
|
-
def delay deadline, ack_id
|
|
216
|
-
@request.modify_deadline_seconds << deadline
|
|
217
|
-
@request.modify_deadline_ack_ids << ack_id
|
|
218
|
-
@total_message_bytes += addl_delay_bytes deadline, ack_id
|
|
219
|
-
end
|
|
220
|
-
|
|
221
|
-
def try_delay deadline, ack_id
|
|
222
|
-
addl_bytes = addl_delay_bytes deadline, ack_id
|
|
223
|
-
return false if total_message_bytes + addl_bytes >= @max_bytes
|
|
224
|
-
|
|
225
|
-
delay deadline, ack_id
|
|
226
|
-
true
|
|
227
|
-
end
|
|
228
|
-
|
|
229
|
-
def addl_delay_bytes deadline, ack_id
|
|
230
|
-
bytes_for_int(deadline) + ack_id.bytesize + 4
|
|
231
|
-
end
|
|
232
|
-
|
|
233
|
-
def bytes_for_int num
|
|
234
|
-
# Ruby 2.0 does not have Integer#bit_length
|
|
235
|
-
return [num].pack("s").bytesize unless num.respond_to? :bit_length
|
|
236
|
-
|
|
237
|
-
(num.bit_length / 8.0).ceil
|
|
238
|
-
end
|
|
239
|
-
|
|
240
|
-
def ready?
|
|
241
|
-
total_message_bytes >= @max_bytes
|
|
242
|
-
end
|
|
243
|
-
|
|
244
|
-
def ack?
|
|
245
|
-
@request.ack_ids.any?
|
|
246
|
-
end
|
|
247
|
-
|
|
248
|
-
def delay?
|
|
249
|
-
@request.modify_deadline_ack_ids.any?
|
|
250
|
-
end
|
|
251
|
-
|
|
252
|
-
def ack_ids
|
|
253
|
-
@request.ack_ids
|
|
254
|
-
end
|
|
255
|
-
|
|
256
|
-
def modify_deadline_hash
|
|
257
|
-
grouped_hash = @request.modify_deadline_ack_ids.zip(
|
|
258
|
-
@request.modify_deadline_seconds
|
|
259
|
-
).group_by { |_ack_id, seconds| seconds }
|
|
260
|
-
Hash[grouped_hash.map { |k, v| [k, v.map(&:first)] }]
|
|
261
|
-
end
|
|
262
|
-
|
|
263
|
-
def total_message_bytes
|
|
264
|
-
@total_message_bytes
|
|
265
|
-
end
|
|
266
|
-
end
|
|
267
|
-
end
|
|
268
|
-
end
|
|
269
|
-
end
|
|
270
|
-
end
|
|
271
|
-
end
|