job_log_path = File.join(@path, "jobs", job_number, "log")
if File.exist? job_log_path then
+ # get job status and send it
+ job_status = ""
+ if job.nil? then
+ get_db_connection() do |db|
+ job_status = db.select_one("SELECT status FROM jobs WHERE id = #{job_number}")[0]
+ end
+ else
+ job_status = job.status
+ end
+ BuildCommServer.send(conn, "JOB STATUS : [[#{job_status}]]")
+
begin
File::Tail::Logfile.open(job_log_path) do |log|
+ # skip log file creation information
+ log.forward(1)
+
+ # send log file information using file-tail
log.tail { |line|
- BuildCommServer.send(conn, line)
+ if line.strip.empty? then next end
+ contents = line.sub(/^[a-zA-Z], \[.*\][ \t]*/,"")
+ BuildCommServer.send(conn, contents)
- if log.eof? and (job.nil? or
- job.status.eql? "FINISHED" or
- job.status.eql? "ERROR" or
- job.status.eql? "CANCELED") then
+ # if read file's last line and job status ended then log file sending done
+ if not job.nil? then job_status = job.status end
+ if log.eof? and
+ (job_status.eql? "FINISHED" or
+ job_status.eql? "ERROR" or
+ job_status.eql? "CANCELED") then
+ # Log file send done. & send job status
+ BuildCommServer.send(conn, "JOB STATUS : [[#{job_status}]]")
break
end
}