Created
May 19, 2009 00:21
-
-
Save libin/113827 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
class Progress | |
require 'action_view/helpers/date_helper' | |
include ActionView::Helpers::DateHelper | |
def initialize(total, interval = 10) | |
@total = total | |
@interval = interval | |
@count = 0 | |
@start = Time.now | |
end | |
def tick | |
@count += 1 | |
if 0 == @count % @interval | |
sofar = Time.now | |
elapsed = sofar - @start | |
puts "been running for #{distance_of_time_in_words(@start, sofar)}" | |
rate = elapsed / @count | |
puts "at a rate of #{distance_of_time_in_words(sofar, (sofar - rate), true)} per item" | |
finish = sofar + ((@total * rate) - elapsed) | |
puts "should finish around #{distance_of_time_in_words(sofar, finish)}" | |
end | |
end | |
end | |
namespace :videos do | |
desc "Remove videos from SpumCo if YouTube also removed them" | |
task :purge => :environment do | |
videos = Video.find(:all, :order => 'created_at asc') | |
progress = Progress.new(videos.size) | |
videos.each do |video| | |
progress.tick | |
video.destroy unless video.still_on_youtube? | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment