Skip to content

Instantly share code, notes, and snippets.

@mago0
Created May 2, 2017 00:23
Show Gist options
  • Save mago0/e299624e6d9d4cf287b5a4963997c88a to your computer and use it in GitHub Desktop.
Save mago0/e299624e6d9d4cf287b5a4963997c88a to your computer and use it in GitHub Desktop.
count = 0
starting_after = nil
while true
customers = Stripe::Customer.all(limit: 100, starting_after: starting_after, created: {'gt' => 1487462400})
break if customers.data.length == 0
cus_threads = []
customers.each do |customer|
cus_threads << Thread.new {
time = Time::now.strftime("%Y/%m/%d-%H:%M:%S")
begin
if (/^loadtest_.*/ =~ customer['email'] && customer['livemode'] != true) then
resp = Stripe::Customer.retrieve(customer['id']).delete
puts "#{count} | #{time} | #{customer['email']} | #{resp['id']} | deleted: #{resp['deleted']}"
count += 1
end
rescue Stripe::RateLimitError => e
puts "#{count} | #{time} | #{customer['email']} | Hit rate-limit"
rescue Stripe::StripeError => e
puts "#{count} | #{time} | #{customer['email']} | Error"
end
}
end
cus_threads.each { |t| t.join }
starting_after = customers.data.last.id
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment