Last active
March 7, 2016 08:41
-
-
Save thomasfl/1a10873c13b0d5038b89 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
require 'thread' | |
require 'date' | |
# Format number of hours, minutes and seconds since start time: | |
def elapsed_time_formatted(start_time) | |
end_time = DateTime.now | |
total_seconds = ((end_time - start_time) * 24 * 60 * 60).to_i | |
seconds = total_seconds % 60 | |
minutes = (total_seconds / 60) % 60 | |
hours = total_seconds / (60 * 60) | |
return format("%02d:%02d:%02d", hours, minutes, seconds) | |
end | |
start_time = DateTime.now | |
done = false | |
Thread.new do | |
## Long running tasks go here | |
4.times do |i| | |
sleep 1 | |
end | |
done = true | |
end | |
# Print time since start every second: | |
while (done == false) do | |
puts elapsed_time_formatted(start_time) | |
sleep(1) | |
end | |
puts "Done." |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Use this as a skeleton if there is a long running process (like really long running tests) and you want to know for how long it has been going on.