Skip to content

Instantly share code, notes, and snippets.

@chooper
Forked from jimdanz/customer_fetch.rb
Last active August 29, 2015 13:56
Show Gist options
  • Save chooper/8924886 to your computer and use it in GitHub Desktop.
Save chooper/8924886 to your computer and use it in GitHub Desktop.
#!/usr/bin/env ruby
require 'stripe'
require 'logger'
if ARGV.length != 2
puts "Usage: #{__FILE__} <api key> <sleep interval>"
exit 1
end
Stripe.api_key = ARGV[0]
sleep_interval = ARGV[1].to_f
$logger = Logger.new(STDOUT)
$logger.level = Logger::INFO
def fetch_customers
begin
before = Time.now
Stripe::Customer.all
after = Time.now
$logger.info "SUCCESS in #{after - before}s"
rescue Stripe::StripeError => e
after = Time.now
$logger.warn "FAILURE in #{after - before}s. Exception: #{e}"
end
end
#while true do
# fetch_customers
# sleep sleep_interval
#end
fetch_customers
source "http://rubygems.org"
gem "stripe"

Magic Incantation

All instructions are assuming you are correctly logged into deploymaster with $APP set to the Ion slot you care about and $USER set to your username.

Installation

bin/run -u $USER -n 50 -a $APP -c 'export BASE=/tmp/stripe_test; mkdir -p "$BASE" && cd "$BASE" && curl https://gist.github.com/chooper/8924886/raw/6f5ea6087bd102defe598fe891c976e3583cd051/Gemfile > "./Gemfile"; curl https://gist.github.com/chooper/8924886/raw/0ddf55bc97b36d741e6fb18d2018849245275ec2/customer_fetch.rb > "./customer_fetch.rb"; bundle install'

Test

bin/run -u $USER -n 50 -a $APP -c 'export BASE=/tmp/stripe_test; cd "$BASE" && bundle exec ruby ./customer_fetch.rb sk_test_SvNt9ppL6U2RxlJ9QR18H9yJ 1'

Cleanup

bin/run -u $USER -n 50 -a $APP -c 'rm -fr /tmp/stripe_test'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment