File: pull_subscription.rb

package info (click to toggle)
ruby-fog-google 1.19.0-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 2,568 kB
  • sloc: ruby: 16,775; makefile: 3
file content (40 lines) | stat: -rw-r--r-- 1,638 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
module Fog
  module Google
    class Pubsub
      class Real
        # Pulls from a subscription. If option 'return_immediately' is
        # false, then this method blocks until one or more messages is
        # available or the remote server closes the connection.
        #
        # @param subscription [Subscription, #to_s] subscription instance or
        #   name of subscription to pull from
        # @param options [Hash] options to modify the pull request
        # @option options [Boolean] :return_immediately if true, method returns
        #   after API call; otherwise the connection is held open until
        #   messages are available or the remote server closes the connection
        #   (defaults to true)
        # @option options [Number] :max_messages maximum number of messages to
        #   retrieve (defaults to 10)
        # @see https://cloud.google.com/pubsub/reference/rest/v1/projects.subscriptions/pull
        def pull_subscription(subscription, options = {})
          defaults = { :return_immediately => true,
                       :max_messages => 10 }
          options = defaults.merge(options)

          pull_request = ::Google::Apis::PubsubV1::PullRequest.new(
            :return_immediately => options[:return_immediately],
            :max_messages => options[:max_messages]
          )

          @pubsub.pull_subscription(subscription, pull_request)
        end
      end

      class Mock
        def pull_subscription(_subscription, _options = { :return_immediately => true, :max_messages => 10 })
          raise Fog::Errors::MockNotImplemented
        end
      end
    end
  end
end