Skip to content

Instantly share code, notes, and snippets.

@PDegenPortnoy
Created September 29, 2014 21:41
Show Gist options
  • Save PDegenPortnoy/9ff3f0e5f0757cd5f743 to your computer and use it in GitHub Desktop.
Save PDegenPortnoy/9ff3f0e5f0757cd5f743 to your computer and use it in GitHub Desktop.
Example code for find_in_batches with calls to Akismet
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