google-cloud-pubsub 1.10.0 → 2.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/AUTHENTICATION.md +2 -1
- data/CHANGELOG.md +59 -0
- data/OVERVIEW.md +26 -58
- data/lib/google-cloud-pubsub.rb +14 -13
- data/lib/google/cloud/pubsub.rb +15 -18
- data/lib/google/cloud/pubsub/async_publisher.rb +2 -3
- data/lib/google/cloud/pubsub/credentials.rb +2 -2
- data/lib/google/cloud/pubsub/message.rb +1 -1
- data/lib/google/cloud/pubsub/project.rb +1 -1
- data/lib/google/cloud/pubsub/received_message.rb +4 -4
- data/lib/google/cloud/pubsub/retry_policy.rb +0 -3
- data/lib/google/cloud/pubsub/service.rb +102 -256
- data/lib/google/cloud/pubsub/subscriber.rb +17 -4
- data/lib/google/cloud/pubsub/subscriber/inventory.rb +5 -2
- data/lib/google/cloud/pubsub/subscriber/stream.rb +3 -4
- data/lib/google/cloud/pubsub/subscription.rb +70 -26
- data/lib/google/cloud/pubsub/subscription/push_config.rb +55 -31
- data/lib/google/cloud/pubsub/topic.rb +49 -18
- data/lib/google/cloud/pubsub/version.rb +1 -1
- metadata +8 -79
- data/lib/google/cloud/pubsub/v1.rb +0 -17
- data/lib/google/cloud/pubsub/v1/credentials.rb +0 -41
- data/lib/google/cloud/pubsub/v1/doc/google/iam/v1/iam_policy.rb +0 -21
- data/lib/google/cloud/pubsub/v1/doc/google/iam/v1/options.rb +0 -21
- data/lib/google/cloud/pubsub/v1/doc/google/iam/v1/policy.rb +0 -21
- data/lib/google/cloud/pubsub/v1/doc/google/protobuf/duration.rb +0 -91
- data/lib/google/cloud/pubsub/v1/doc/google/protobuf/empty.rb +0 -29
- data/lib/google/cloud/pubsub/v1/doc/google/protobuf/field_mask.rb +0 -222
- data/lib/google/cloud/pubsub/v1/doc/google/protobuf/timestamp.rb +0 -113
- data/lib/google/cloud/pubsub/v1/doc/google/pubsub/v1/pubsub.rb +0 -833
- data/lib/google/cloud/pubsub/v1/doc/google/type/expr.rb +0 -19
- data/lib/google/cloud/pubsub/v1/publisher_client.rb +0 -928
- data/lib/google/cloud/pubsub/v1/publisher_client_config.json +0 -120
- data/lib/google/cloud/pubsub/v1/subscriber_client.rb +0 -1466
- data/lib/google/cloud/pubsub/v1/subscriber_client_config.json +0 -153
- data/lib/google/pubsub/v1/pubsub_pb.rb +0 -269
- data/lib/google/pubsub/v1/pubsub_services_pb.rb +0 -215
@@ -78,7 +78,7 @@ module Google
|
|
78
78
|
# end
|
79
79
|
# end
|
80
80
|
#
|
81
|
-
# topic.async_publisher.stop
|
81
|
+
# topic.async_publisher.stop!
|
82
82
|
#
|
83
83
|
def async_publisher
|
84
84
|
@async_publisher
|
@@ -275,7 +275,10 @@ module Google
|
|
275
275
|
# 604,800 seconds (7 days) or less than 600 seconds (10 minutes).
|
276
276
|
# Default is 604,800 seconds (7 days).
|
277
277
|
# @param [String] endpoint A URL locating the endpoint to which messages
|
278
|
-
# should be pushed.
|
278
|
+
# should be pushed. The parameters `push_config` and `endpoint` should not both be provided.
|
279
|
+
# @param [Google::Cloud::PubSub::Subscription::PushConfig] push_config The configuration for a push delivery
|
280
|
+
# endpoint that should contain the endpoint, and can contain authentication data (OIDC token authentication).
|
281
|
+
# The parameters `push_config` and `endpoint` should not both be provided.
|
279
282
|
# @param [Hash] labels A hash of user-provided labels associated with
|
280
283
|
# the subscription. You can use these to organize and group your
|
281
284
|
# subscriptions. Label keys and values can be no longer than 63
|
@@ -306,9 +309,6 @@ module Google
|
|
306
309
|
# will be retried as soon as possible for healthy subscribers. Retry Policy will be triggered on NACKs or
|
307
310
|
# acknowledgement deadline exceeded events for a given message.
|
308
311
|
#
|
309
|
-
# **EXPERIMENTAL:** This API might be changed in backward-incompatible ways and is not recommended for
|
310
|
-
# production use. It is not subject to any SLA or deprecation policy.
|
311
|
-
#
|
312
312
|
# @return [Google::Cloud::PubSub::Subscription]
|
313
313
|
#
|
314
314
|
# @example
|
@@ -320,15 +320,25 @@ module Google
|
|
320
320
|
# sub = topic.subscribe "my-topic-sub"
|
321
321
|
# sub.name # => "my-topic-sub"
|
322
322
|
#
|
323
|
-
# @example Wait 2 minutes for acknowledgement
|
323
|
+
# @example Wait 2 minutes for acknowledgement:
|
324
324
|
# require "google/cloud/pubsub"
|
325
325
|
#
|
326
326
|
# pubsub = Google::Cloud::PubSub.new
|
327
327
|
#
|
328
328
|
# topic = pubsub.topic "my-topic"
|
329
329
|
# sub = topic.subscribe "my-topic-sub",
|
330
|
-
# deadline: 120
|
331
|
-
#
|
330
|
+
# deadline: 120
|
331
|
+
#
|
332
|
+
# @example Configure a push endpoint:
|
333
|
+
# require "google/cloud/pubsub"
|
334
|
+
#
|
335
|
+
# pubsub = Google::Cloud::PubSub.new
|
336
|
+
# topic = pubsub.topic "my-topic"
|
337
|
+
#
|
338
|
+
# push_config = Google::Cloud::PubSub::Subscription::PushConfig.new endpoint: "http://example.net/callback"
|
339
|
+
# push_config.set_oidc_token "service-account@example.net", "audience-header-value"
|
340
|
+
#
|
341
|
+
# sub = topic.subscribe "my-subscription", push_config: push_config
|
332
342
|
#
|
333
343
|
# @example Configure a Dead Letter Queues policy:
|
334
344
|
# require "google/cloud/pubsub"
|
@@ -361,19 +371,40 @@ module Google
|
|
361
371
|
# retry_policy = Google::Cloud::PubSub::RetryPolicy.new minimum_backoff: 5, maximum_backoff: 300
|
362
372
|
# sub = topic.subscribe "my-topic-sub", retry_policy: retry_policy
|
363
373
|
#
|
364
|
-
def subscribe subscription_name,
|
365
|
-
|
366
|
-
|
374
|
+
def subscribe subscription_name,
|
375
|
+
deadline: nil,
|
376
|
+
retain_acked: false,
|
377
|
+
retention: nil,
|
378
|
+
endpoint: nil,
|
379
|
+
push_config: nil,
|
380
|
+
labels: nil,
|
381
|
+
message_ordering: nil,
|
382
|
+
filter: nil,
|
383
|
+
dead_letter_topic: nil,
|
384
|
+
dead_letter_max_delivery_attempts: nil,
|
385
|
+
retry_policy: nil
|
367
386
|
ensure_service!
|
368
|
-
|
369
|
-
|
370
|
-
|
387
|
+
if push_config && endpoint
|
388
|
+
raise ArgumentError, "endpoint and push_config were both provided. Please provide only one."
|
389
|
+
end
|
390
|
+
push_config = Google::Cloud::PubSub::Subscription::PushConfig.new endpoint: endpoint if endpoint
|
391
|
+
|
392
|
+
options = {
|
393
|
+
deadline: deadline,
|
394
|
+
retain_acked: retain_acked,
|
395
|
+
retention: retention,
|
396
|
+
labels: labels,
|
397
|
+
message_ordering: message_ordering,
|
398
|
+
filter: filter,
|
399
|
+
dead_letter_max_delivery_attempts: dead_letter_max_delivery_attempts
|
400
|
+
}
|
371
401
|
|
372
402
|
options[:dead_letter_topic_name] = dead_letter_topic.name if dead_letter_topic
|
373
403
|
if options[:dead_letter_max_delivery_attempts] && !options[:dead_letter_topic_name]
|
374
404
|
# Service error message "3:Invalid resource name given (name=)." does not identify param.
|
375
405
|
raise ArgumentError, "dead_letter_topic is required with dead_letter_max_delivery_attempts"
|
376
406
|
end
|
407
|
+
options[:push_config] = push_config.to_grpc if push_config
|
377
408
|
options[:retry_policy] = retry_policy.to_grpc if retry_policy
|
378
409
|
grpc = service.create_subscription name, subscription_name, options
|
379
410
|
Subscription.from_grpc grpc, service
|
@@ -590,7 +621,7 @@ module Google
|
|
590
621
|
# end
|
591
622
|
#
|
592
623
|
# # Shut down the publisher when ready to stop publishing messages.
|
593
|
-
# topic.async_publisher.stop
|
624
|
+
# topic.async_publisher.stop!
|
594
625
|
#
|
595
626
|
# @example A message can be published using a File object:
|
596
627
|
# require "google/cloud/pubsub"
|
@@ -602,7 +633,7 @@ module Google
|
|
602
633
|
# topic.publish_async file
|
603
634
|
#
|
604
635
|
# # Shut down the publisher when ready to stop publishing messages.
|
605
|
-
# topic.async_publisher.stop
|
636
|
+
# topic.async_publisher.stop!
|
606
637
|
#
|
607
638
|
# @example Additionally, a message can be published with attributes:
|
608
639
|
# require "google/cloud/pubsub"
|
@@ -614,7 +645,7 @@ module Google
|
|
614
645
|
# foo: :bar, this: :that
|
615
646
|
#
|
616
647
|
# # Shut down the publisher when ready to stop publishing messages.
|
617
|
-
# topic.async_publisher.stop
|
648
|
+
# topic.async_publisher.stop!
|
618
649
|
#
|
619
650
|
# @example Ordered messages are supported using ordering_key:
|
620
651
|
# require "google/cloud/pubsub"
|
@@ -631,7 +662,7 @@ module Google
|
|
631
662
|
# ordering_key: "task-key"
|
632
663
|
#
|
633
664
|
# # Shut down the publisher when ready to stop publishing messages.
|
634
|
-
# topic.async_publisher.stop
|
665
|
+
# topic.async_publisher.stop!
|
635
666
|
#
|
636
667
|
def publish_async data = nil, attributes = nil, ordering_key: nil, **extra_attrs, &callback
|
637
668
|
ensure_service!
|
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:
|
4
|
+
version: 2.3.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: 2020-
|
12
|
+
date: 2020-11-18 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: concurrent-ruby
|
@@ -31,82 +31,28 @@ dependencies:
|
|
31
31
|
requirements:
|
32
32
|
- - "~>"
|
33
33
|
- !ruby/object:Gem::Version
|
34
|
-
version: '1.
|
34
|
+
version: '1.5'
|
35
35
|
type: :runtime
|
36
36
|
prerelease: false
|
37
37
|
version_requirements: !ruby/object:Gem::Requirement
|
38
38
|
requirements:
|
39
39
|
- - "~>"
|
40
40
|
- !ruby/object:Gem::Version
|
41
|
-
version: '1.
|
41
|
+
version: '1.5'
|
42
42
|
- !ruby/object:Gem::Dependency
|
43
|
-
name: google-
|
43
|
+
name: google-cloud-pubsub-v1
|
44
44
|
requirement: !ruby/object:Gem::Requirement
|
45
45
|
requirements:
|
46
46
|
- - "~>"
|
47
47
|
- !ruby/object:Gem::Version
|
48
|
-
version: '
|
48
|
+
version: '0.0'
|
49
49
|
type: :runtime
|
50
50
|
prerelease: false
|
51
51
|
version_requirements: !ruby/object:Gem::Requirement
|
52
52
|
requirements:
|
53
53
|
- - "~>"
|
54
54
|
- !ruby/object:Gem::Version
|
55
|
-
version: '
|
56
|
-
- !ruby/object:Gem::Dependency
|
57
|
-
name: googleapis-common-protos
|
58
|
-
requirement: !ruby/object:Gem::Requirement
|
59
|
-
requirements:
|
60
|
-
- - ">="
|
61
|
-
- !ruby/object:Gem::Version
|
62
|
-
version: 1.3.9
|
63
|
-
- - "<"
|
64
|
-
- !ruby/object:Gem::Version
|
65
|
-
version: '2.0'
|
66
|
-
type: :runtime
|
67
|
-
prerelease: false
|
68
|
-
version_requirements: !ruby/object:Gem::Requirement
|
69
|
-
requirements:
|
70
|
-
- - ">="
|
71
|
-
- !ruby/object:Gem::Version
|
72
|
-
version: 1.3.9
|
73
|
-
- - "<"
|
74
|
-
- !ruby/object:Gem::Version
|
75
|
-
version: '2.0'
|
76
|
-
- !ruby/object:Gem::Dependency
|
77
|
-
name: googleapis-common-protos-types
|
78
|
-
requirement: !ruby/object:Gem::Requirement
|
79
|
-
requirements:
|
80
|
-
- - ">="
|
81
|
-
- !ruby/object:Gem::Version
|
82
|
-
version: 1.0.4
|
83
|
-
- - "<"
|
84
|
-
- !ruby/object:Gem::Version
|
85
|
-
version: '2.0'
|
86
|
-
type: :runtime
|
87
|
-
prerelease: false
|
88
|
-
version_requirements: !ruby/object:Gem::Requirement
|
89
|
-
requirements:
|
90
|
-
- - ">="
|
91
|
-
- !ruby/object:Gem::Version
|
92
|
-
version: 1.0.4
|
93
|
-
- - "<"
|
94
|
-
- !ruby/object:Gem::Version
|
95
|
-
version: '2.0'
|
96
|
-
- !ruby/object:Gem::Dependency
|
97
|
-
name: grpc-google-iam-v1
|
98
|
-
requirement: !ruby/object:Gem::Requirement
|
99
|
-
requirements:
|
100
|
-
- - "~>"
|
101
|
-
- !ruby/object:Gem::Version
|
102
|
-
version: 0.6.9
|
103
|
-
type: :runtime
|
104
|
-
prerelease: false
|
105
|
-
version_requirements: !ruby/object:Gem::Requirement
|
106
|
-
requirements:
|
107
|
-
- - "~>"
|
108
|
-
- !ruby/object:Gem::Version
|
109
|
-
version: 0.6.9
|
55
|
+
version: '0.0'
|
110
56
|
- !ruby/object:Gem::Dependency
|
111
57
|
name: autotest-suffix
|
112
58
|
requirement: !ruby/object:Gem::Requirement
|
@@ -293,24 +239,7 @@ files:
|
|
293
239
|
- lib/google/cloud/pubsub/subscription/push_config.rb
|
294
240
|
- lib/google/cloud/pubsub/topic.rb
|
295
241
|
- lib/google/cloud/pubsub/topic/list.rb
|
296
|
-
- lib/google/cloud/pubsub/v1.rb
|
297
|
-
- lib/google/cloud/pubsub/v1/credentials.rb
|
298
|
-
- lib/google/cloud/pubsub/v1/doc/google/iam/v1/iam_policy.rb
|
299
|
-
- lib/google/cloud/pubsub/v1/doc/google/iam/v1/options.rb
|
300
|
-
- lib/google/cloud/pubsub/v1/doc/google/iam/v1/policy.rb
|
301
|
-
- lib/google/cloud/pubsub/v1/doc/google/protobuf/duration.rb
|
302
|
-
- lib/google/cloud/pubsub/v1/doc/google/protobuf/empty.rb
|
303
|
-
- lib/google/cloud/pubsub/v1/doc/google/protobuf/field_mask.rb
|
304
|
-
- lib/google/cloud/pubsub/v1/doc/google/protobuf/timestamp.rb
|
305
|
-
- lib/google/cloud/pubsub/v1/doc/google/pubsub/v1/pubsub.rb
|
306
|
-
- lib/google/cloud/pubsub/v1/doc/google/type/expr.rb
|
307
|
-
- lib/google/cloud/pubsub/v1/publisher_client.rb
|
308
|
-
- lib/google/cloud/pubsub/v1/publisher_client_config.json
|
309
|
-
- lib/google/cloud/pubsub/v1/subscriber_client.rb
|
310
|
-
- lib/google/cloud/pubsub/v1/subscriber_client_config.json
|
311
242
|
- lib/google/cloud/pubsub/version.rb
|
312
|
-
- lib/google/pubsub/v1/pubsub_pb.rb
|
313
|
-
- lib/google/pubsub/v1/pubsub_services_pb.rb
|
314
243
|
homepage: https://github.com/googleapis/google-cloud-ruby/tree/master/google-cloud-pubsub
|
315
244
|
licenses:
|
316
245
|
- Apache-2.0
|
@@ -330,7 +259,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
330
259
|
- !ruby/object:Gem::Version
|
331
260
|
version: '0'
|
332
261
|
requirements: []
|
333
|
-
rubygems_version: 3.1.
|
262
|
+
rubygems_version: 3.1.4
|
334
263
|
signing_key:
|
335
264
|
specification_version: 4
|
336
265
|
summary: API Client library for Google Cloud Pub/Sub
|
@@ -1,17 +0,0 @@
|
|
1
|
-
# Copyright 2015 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 "google/cloud/pubsub/v1/publisher_client"
|
17
|
-
require "google/cloud/pubsub/v1/subscriber_client"
|
@@ -1,41 +0,0 @@
|
|
1
|
-
# Copyright 2020 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 "googleauth"
|
17
|
-
|
18
|
-
module Google
|
19
|
-
module Cloud
|
20
|
-
module PubSub
|
21
|
-
module V1
|
22
|
-
class Credentials < Google::Auth::Credentials
|
23
|
-
SCOPE = ["https://www.googleapis.com/auth/pubsub"].freeze
|
24
|
-
PATH_ENV_VARS = %w(PUBSUB_CREDENTIALS
|
25
|
-
PUBSUB_KEYFILE
|
26
|
-
GOOGLE_CLOUD_CREDENTIALS
|
27
|
-
GOOGLE_CLOUD_KEYFILE
|
28
|
-
GCLOUD_KEYFILE)
|
29
|
-
JSON_ENV_VARS = %w(PUBSUB_CREDENTIALS_JSON
|
30
|
-
PUBSUB_KEYFILE_JSON
|
31
|
-
GOOGLE_CLOUD_CREDENTIALS_JSON
|
32
|
-
GOOGLE_CLOUD_KEYFILE_JSON
|
33
|
-
GCLOUD_KEYFILE_JSON)
|
34
|
-
DEFAULT_PATHS = ["~/.config/gcloud/application_default_credentials.json"]
|
35
|
-
end
|
36
|
-
end
|
37
|
-
end
|
38
|
-
|
39
|
-
Pubsub = PubSub unless const_defined? :Pubsub
|
40
|
-
end
|
41
|
-
end
|
@@ -1,21 +0,0 @@
|
|
1
|
-
# Copyright 2020 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
|
-
module Google
|
17
|
-
module Iam
|
18
|
-
module V1
|
19
|
-
end
|
20
|
-
end
|
21
|
-
end
|
@@ -1,21 +0,0 @@
|
|
1
|
-
# Copyright 2020 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
|
-
module Google
|
17
|
-
module Iam
|
18
|
-
module V1
|
19
|
-
end
|
20
|
-
end
|
21
|
-
end
|
@@ -1,21 +0,0 @@
|
|
1
|
-
# Copyright 2020 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
|
-
module Google
|
17
|
-
module Iam
|
18
|
-
module V1
|
19
|
-
end
|
20
|
-
end
|
21
|
-
end
|
@@ -1,91 +0,0 @@
|
|
1
|
-
# Copyright 2020 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
|
-
module Google
|
17
|
-
module Protobuf
|
18
|
-
# A Duration represents a signed, fixed-length span of time represented
|
19
|
-
# as a count of seconds and fractions of seconds at nanosecond
|
20
|
-
# resolution. It is independent of any calendar and concepts like "day"
|
21
|
-
# or "month". It is related to Timestamp in that the difference between
|
22
|
-
# two Timestamp values is a Duration and it can be added or subtracted
|
23
|
-
# from a Timestamp. Range is approximately +-10,000 years.
|
24
|
-
#
|
25
|
-
# = Examples
|
26
|
-
#
|
27
|
-
# Example 1: Compute Duration from two Timestamps in pseudo code.
|
28
|
-
#
|
29
|
-
# Timestamp start = ...;
|
30
|
-
# Timestamp end = ...;
|
31
|
-
# Duration duration = ...;
|
32
|
-
#
|
33
|
-
# duration.seconds = end.seconds - start.seconds;
|
34
|
-
# duration.nanos = end.nanos - start.nanos;
|
35
|
-
#
|
36
|
-
# if (duration.seconds < 0 && duration.nanos > 0) {
|
37
|
-
# duration.seconds += 1;
|
38
|
-
# duration.nanos -= 1000000000;
|
39
|
-
# } else if (durations.seconds > 0 && duration.nanos < 0) {
|
40
|
-
# duration.seconds -= 1;
|
41
|
-
# duration.nanos += 1000000000;
|
42
|
-
# }
|
43
|
-
#
|
44
|
-
# Example 2: Compute Timestamp from Timestamp + Duration in pseudo code.
|
45
|
-
#
|
46
|
-
# Timestamp start = ...;
|
47
|
-
# Duration duration = ...;
|
48
|
-
# Timestamp end = ...;
|
49
|
-
#
|
50
|
-
# end.seconds = start.seconds + duration.seconds;
|
51
|
-
# end.nanos = start.nanos + duration.nanos;
|
52
|
-
#
|
53
|
-
# if (end.nanos < 0) {
|
54
|
-
# end.seconds -= 1;
|
55
|
-
# end.nanos += 1000000000;
|
56
|
-
# } else if (end.nanos >= 1000000000) {
|
57
|
-
# end.seconds += 1;
|
58
|
-
# end.nanos -= 1000000000;
|
59
|
-
# }
|
60
|
-
#
|
61
|
-
# Example 3: Compute Duration from datetime.timedelta in Python.
|
62
|
-
#
|
63
|
-
# td = datetime.timedelta(days=3, minutes=10)
|
64
|
-
# duration = Duration()
|
65
|
-
# duration.FromTimedelta(td)
|
66
|
-
#
|
67
|
-
# = JSON Mapping
|
68
|
-
#
|
69
|
-
# In JSON format, the Duration type is encoded as a string rather than an
|
70
|
-
# object, where the string ends in the suffix "s" (indicating seconds) and
|
71
|
-
# is preceded by the number of seconds, with nanoseconds expressed as
|
72
|
-
# fractional seconds. For example, 3 seconds with 0 nanoseconds should be
|
73
|
-
# encoded in JSON format as "3s", while 3 seconds and 1 nanosecond should
|
74
|
-
# be expressed in JSON format as "3.000000001s", and 3 seconds and 1
|
75
|
-
# microsecond should be expressed in JSON format as "3.000001s".
|
76
|
-
# @!attribute [rw] seconds
|
77
|
-
# @return [Integer]
|
78
|
-
# Signed seconds of the span of time. Must be from -315,576,000,000
|
79
|
-
# to +315,576,000,000 inclusive. Note: these bounds are computed from:
|
80
|
-
# 60 sec/min * 60 min/hr * 24 hr/day * 365.25 days/year * 10000 years
|
81
|
-
# @!attribute [rw] nanos
|
82
|
-
# @return [Integer]
|
83
|
-
# Signed fractions of a second at nanosecond resolution of the span
|
84
|
-
# of time. Durations less than one second are represented with a 0
|
85
|
-
# `seconds` field and a positive or negative `nanos` field. For durations
|
86
|
-
# of one second or more, a non-zero value for the `nanos` field must be
|
87
|
-
# of the same sign as the `seconds` field. Must be from -999,999,999
|
88
|
-
# to +999,999,999 inclusive.
|
89
|
-
class Duration; end
|
90
|
-
end
|
91
|
-
end
|