Skip to content

Instantly share code, notes, and snippets.

@elliottkember
Created August 22, 2013 15:38
Show Gist options
  • Save elliottkember/6308835 to your computer and use it in GitHub Desktop.
Save elliottkember/6308835 to your computer and use it in GitHub Desktop.
Check your Heroku apps for the Memcache add-on, which is being discontinued.
apps = `heroku apps`.split("\n")
apps.each do |app|
next if app.include? "My Apps"
app = app.split(" ")[0]
gems = `heroku addons --app #{app}`.split("\n")
gems.each do |gem|
if gem.include? "memcache:"
puts "#{app} is using #{gem}"
end
end
end
@bjeanes
Copy link

bjeanes commented Aug 22, 2013

Or if you aren't a Rubyist (I am, but others may not be), have something to run in your shell:

for app in `heroku apps | grep -vE '===|^$'`; do 
  heroku addons --app $app | grep "memcache:" &>/dev/null && 
    echo $app is using memcache add-on
done

@brandur
Copy link

brandur commented Aug 22, 2013

Awesome! You can even try using the platform API to avoid that CLI start-up overhead ;)

require "excon"
require "multi_json"

#
# grab your access token from ~/.netrc under the section api.heroku.com
#

abort("usage: ruby find-memcache.rb <access_token>") unless ARGV[0]
access_token = ARGV[0]

api = Excon.new(
  "https://api.heroku.com",
  headers: {
    "Accept"        => "application/vnd.heroku+json; version=3",
    "Authorization" => "Bearer #{access_token}",
  }
)

apps = MultiJson.decode(api.get(
  path: "/apps",
  expects: 200
).body)

apps.each do |app|
  addons = MultiJson.decode(api.get(
    path: "/apps/#{app["id"]}/addons",
    expects: 200
  ).body)
  puts app["name"] if addons.any? { |a| a["plan"]["name"] =~ /^memcache:/ }
end

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment