Created
September 29, 2014 21:41
-
-
Save PDegenPortnoy/9ff3f0e5f0757cd5f743 to your computer and use it in GitHub Desktop.
Example code for find_in_batches with calls to Akismet
This file contains 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
def setup | |
@file = CSV.open() | |
@file.write(header) | |
end | |
def header | |
%w(account_id name url blah blorg is_spam) | |
end | |
def check_records | |
iterations = 0 | |
Account.find_in_batches(:conditions => "created_at < now() - interval '1 year'") do |accounts| | |
accounts.each do | account| | |
# Call Akismet | |
is_spam = Akismet::Client.check_comment() | |
# Write to CSV | |
@file.write(accout.id, account.name, account.url, ...., is_spam) | |
end | |
# Are we done? We want only 20 iterations | |
iterations += 1 | |
break if iterations > = 20 | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment