def query_job_log(job_number, conn)
@log.info "Sending job log : #{job_number}"
- job = nil
job_status = ""
- (@jobmgr.jobs + @jobmgr.internal_jobs + @jobmgr.reverse_build_jobs).each do |manager_job|
- if manager_job.id.eql? job_number then
- job = manager_job
- end
- end
+ job = @jobmgr.search_job(job_number)
Thread.new do
job_log_path = File.join(@path, "jobs", job_number, "log")
File::Tail::Logfile.open(job_log_path) do |log|
log.interval = 0.05
# send log file information using file-tail
- log.tail { |line|
- if line.strip.empty? then next end
+ log.tail do |line|
BuildCommServer.send(conn, line)
- # Send status when changed status
- if (not job.nil?) and (not job.status.eql?(job_status)) then
- job_status = job.status
- BuildCommServer.send(conn, "=JOB_STATUS,#{job_status}")
- end
-
- # if read file's last line and job status ended then log file sending done
- if log.eof? and (job.nil? or
- job.status.eql? "FINISHED" or
- job.status.eql? "ERROR" or
- job.status.eql? "CANCELED") then
+ if not job.nil? then
+ # Send status when changed status
+ if not job.status.eql? job_status then
+ job_status = job.status
+ BuildCommServer.send(conn, "=JOB_STATUS,#{job_status}")
+ end
- # Log file send done. & send job status
- get_db_connection() do |db|
- job_status = db.select_one("SELECT status FROM jobs WHERE id = #{job_number}")[0]
+ if job.status.eql? "FINISHED" or job.status.eql? "ERROR" or job.status.eql? "CANCELED" then
+ log.return_if_eof = true
+ end
+ else
+ if log.eof? then
+ break
end
- BuildCommServer.send(conn, "=JOB_STATUS,#{job_status}")
- break
end
- }
+ end
end
rescue => e
@log.error e.message
else
@log.error "Can't find job log file : #{job_log_path}"
BuildCommServer.send(conn, "Can't find job log file : #{job_number}")
+ BuildCommServer.send(conn, "=LOG_ERROR")
+ end
+
+ get_db_connection() do |db|
+ job_status = db.select_one("SELECT status FROM jobs WHERE id = #{job_number}")[0]
end
+ BuildCommServer.send(conn, "=JOB_STATUS,#{job_status}")
BuildCommServer.send_end(conn)
BuildCommServer.disconnect(conn)