Created
May 2, 2017 00:23
-
-
Save mago0/e299624e6d9d4cf287b5a4963997c88a to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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