File: received_message.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,231 bytes parent folder | download | duplicates (5)
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
require "fog/core/model"

module Fog
  module Google
    class Pubsub
      # Represents a ReceivedMessage retrieved from a Google Pubsub
      # subscription. Note that ReceivedMessages are immutable.
      #
      # @see https://cloud.google.com/pubsub/reference/rest/v1/projects.subscriptions/pull#ReceivedMessage
      class ReceivedMessage < Fog::Model
        identity :ack_id, :aliases => "ackId"

        attribute :message

        def initialize(new_attributes = {})
          # Here we secretly store the subscription name we were received on
          # in order to support #acknowledge
          attributes = new_attributes.clone
          @subscription_name = attributes.delete(:subscription_name)
          super(attributes)
        end

        # Acknowledges a message.
        #
        # @see https://cloud.google.com/pubsub/reference/rest/v1/projects.subscriptions/acknowledge
        def acknowledge
          requires :ack_id

          service.acknowledge_subscription(@subscription_name, [ack_id])
          nil
        end

        def reload
          # Message is immutable - do nothing
          Fog::Logger.warning("#reload called on immutable ReceivedMessage")
        end
      end
    end
  end
end