Class: Magellan::Gcs::Proxy::PubsubSubscription
- Inherits:
-
Object
- Object
- Magellan::Gcs::Proxy::PubsubSubscription
- Defined in:
- lib/magellan/gcs/proxy/pubsub_subscription.rb
Defined Under Namespace
Classes: MessageWrapper
Instance Attribute Summary collapse
-
#delay ⇒ Object
readonly
Returns the value of attribute delay.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
Instance Method Summary collapse
-
#initialize(name, delay: 1) ⇒ PubsubSubscription
constructor
A new instance of PubsubSubscription.
- #listen ⇒ Object
- #pull_req ⇒ Object
- #wait_for_message ⇒ Object
Constructor Details
#initialize(name, delay: 1) ⇒ PubsubSubscription
Returns a new instance of PubsubSubscription.
9 10 11 12 |
# File 'lib/magellan/gcs/proxy/pubsub_subscription.rb', line 9 def initialize(name, delay: 1) @name = name @delay = delay end |
Instance Attribute Details
#delay ⇒ Object (readonly)
Returns the value of attribute delay.
8 9 10 |
# File 'lib/magellan/gcs/proxy/pubsub_subscription.rb', line 8 def delay @delay end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
8 9 10 |
# File 'lib/magellan/gcs/proxy/pubsub_subscription.rb', line 8 def name @name end |
Instance Method Details
#listen ⇒ Object
14 15 16 17 18 19 20 21 22 |
# File 'lib/magellan/gcs/proxy/pubsub_subscription.rb', line 14 def listen loop do if msg = yield msg else sleep delay end end end |
#pull_req ⇒ Object
24 25 26 |
# File 'lib/magellan/gcs/proxy/pubsub_subscription.rb', line 24 def pull_req @pull_req ||= Google::Apis::PubsubV1::PullRequest.new(max_messages: 1, return_immediately: true) end |
#wait_for_message ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/magellan/gcs/proxy/pubsub_subscription.rb', line 28 def # #<Google::Apis::PubsubV1::ReceivedMessage:0x007fdc440b58d8 # @ack_id="...", # @message=#<Google::Apis::PubsubV1::Message:0x007fdc440be140 # @attributes={"download_files"=>"[\"gs://bucket1/path/to/file1\"]"}, # @message_id="50414480536440", # @publish_time="2016-12-17T08:08:35.599Z">> res = GCP.pubsub.pull_subscription(name, pull_req) msg = (res. || []).first msg.nil? ? nil : MessageWrapper.new(self, msg) end |