GoogleCloudPlatform/getting-started-ruby

Pub/Sub Example Should Delete Subscription

Closed this issue · 0 comments

I'm just learning to use pub/sub but shouldn't the worker code in your example delete the subscription when the program terminates?

begin
  subscription = topic.subscription "lookup_book_details"

  topic.subscribe "lookup_book_details" unless subscription.exists?

  subscription.listen autoack: true do |message|
    Rails.logger.info "Book lookup request (#{message.data})"

    book_id = message.data.to_i
    book    = Book.find_by_id book_id

    LookupBookDetailsJob.perform_now book if book
  end
ensure
  subscription.delete unless subscription.nil?
end

If this subscription is automatically cleaned up, please ignore this. It didn't seem to be the case when I looked at the Cloud Console but as I said, I'm new to Pub/Sub.