lib/google/cloud/pubsub/subscriber/inventory.rb in google-cloud-pubsub-1.4.0 vs lib/google/cloud/pubsub/subscriber/inventory.rb in google-cloud-pubsub-1.5.0

- old
+ new

@@ -28,18 +28,19 @@ end end include MonitorMixin - attr_reader :stream, :limit, :bytesize, :extension + attr_reader :stream, :limit, :bytesize, :extension, :max_duration_per_lease_extension - def initialize stream, limit:, bytesize:, extension: + def initialize stream, limit:, bytesize:, extension:, max_duration_per_lease_extension: super() @stream = stream @limit = limit @bytesize = bytesize @extension = extension + @max_duration_per_lease_extension = max_duration_per_lease_extension @inventory = {} @wait_cond = new_cond end def ack_ids @@ -150,10 +151,12 @@ def calc_target Time.now + calc_delay end def calc_delay - (stream.subscriber.deadline - 3) * rand(0.8..0.9) + delay = (stream.subscriber.deadline - 3) * rand(0.8..0.9) + delay = [delay, max_duration_per_lease_extension].min if max_duration_per_lease_extension.positive? + delay end end end end