module Osbourne::ExistingSubscriptions

Attributes

existing_subscriptions[R]

Public Instance Methods

clear_subscriptions_for(topic) click to toggle source
# File lib/osbourne/existing_subscriptions.rb, line 20
def clear_subscriptions_for(topic)
  Osbourne.cache.delete("osbourne_existng_subs_for_#{topic.name}")
end
existing_subscriptions_for(topic) click to toggle source
# File lib/osbourne/existing_subscriptions.rb, line 6
def existing_subscriptions_for(topic)
  Osbourne.cache.delete("osbourne_existng_subs_for_#{topic.name}")
  Osbourne.cache.fetch("osbourne_existng_subs_for_#{topic.name}") do
    results = []
    handled = Osbourne.lock.try_with_lock("osbourne_lock_subs_for_#{topic.name}") do
      results = fetch_existing_subscriptions_for(topic)
    end
    return results if handled

    sleep(0.5)
    existing_subscriptions_for(topic)
  end
end

Private Instance Methods

fetch_existing_subscriptions_for(topic) click to toggle source
# File lib/osbourne/existing_subscriptions.rb, line 26
def fetch_existing_subscriptions_for(topic)
  results = []
  r = nil
  loop do
    params = {topic_arn: topic.arn}
    params[:next_token] = r.next_token if r.try(:next_token)
    r = Osbourne.sns_client.list_subscriptions_by_topic(params)
    results << r.subscriptions.map(&:endpoint)
    break unless r.try(:next_token).presence
  end
  results.flatten.uniq
end