Skip to content

Instantly share code, notes, and snippets.

@theinventor
Created October 1, 2012 23:03
Show Gist options
  • Save theinventor/3815067 to your computer and use it in GitHub Desktop.
Save theinventor/3815067 to your computer and use it in GitHub Desktop.
Rake Task Template
namespace :some_thingy do
task :my_big_fixer, [:production_run] => :environment do |t, args|
production_run = args[:production_run] == "true"
ap "doing a dry run" unless production_run
my_logger = Logger.new("#{Rails.root}/log/my_thingy.log")
require 'progress_bar'
bar = ProgressBar.new(User.all.count) # pass the total for the progress bar
my_logger.info "Starting at #{Time.now}"
User.all.each do |user|
#do something if production_run
bar.increment!
my_logger.info "User: #{user.id} a thing happened"
end
my_logger.info "Ending at #{Time.now}"
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment