Skip to content

Instantly share code, notes, and snippets.

@arbarlow
Created October 9, 2009 16:47
Show Gist options
  • Save arbarlow/206170 to your computer and use it in GitHub Desktop.
Save arbarlow/206170 to your computer and use it in GitHub Desktop.
#/usr/bin/ruby
require 'rubygems'
require 'activerecord'
ActiveRecord::Base.establish_connection(
:adapter => "mysql",
:host => "localhost",
:username => "root",
:password => "",
:database => "lame"
)
class Job < ActiveRecord::Base ; end
job = Job.find(1)
loop do
begin
log = File.open("logFile", "r")
log = log.read
percentage = log.scan(/(\d+%)/).last
timespent = log.scan(/\d:\d\d\//).last.chomp("/").split(":")
time_eta = log.scan(/\d:\d\d\|/).last.chomp("|").split(":")
timespent_seconds = (timespent[0].to_i * 60) + timespent[1].to_i
time_eta_seconds = (time_eta[0].to_i * 60) + time_eta[1].to_i
timeleft = time_eta_seconds - timespent_seconds
if percentage.to_s == "99%"
job.percent = 100
job.finished_at = Time.now
job.completed = true
job.save
break
elsif percentage.to_s == "100%"
job.percent = 100
job.finished_at = Time.now
job.completed = true
job.save
break
else
job.percent = percentage[0].chomp("%").to_i
job.save
end
rescue
puts "Error"
end
sleep 2
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment