Skip to content

Instantly share code, notes, and snippets.

@phudgins
Created May 10, 2011 13:13
Show Gist options
  • Save phudgins/964441 to your computer and use it in GitHub Desktop.
Save phudgins/964441 to your computer and use it in GitHub Desktop.
Determining the estimated completion of Delayed Jobs
include ActionView::Helpers::DateHelper
def time_remaining
start_count = Delayed::Job.count
if start_count == 0
rate = 0
start_time = Time.now
time_remaining = distance_of_time_in_words(start_time, start_time)
else
sleep(10)
end_count = Delayed::Job.count
delta = end_count - start_count
rate = delta.abs.to_f/10.0
seconds_remaining = (end_count.to_f/rate).round
estimated_completion = Time.now + seconds_remaining.seconds
start_time = Time.now
time_remaining = distance_of_time_in_words(start_time, estimated_completion)
end
[rate, time_remaining]
end
time_remaining
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment