From: Sungmin kim Date: Tue, 2 Apr 2013 11:44:26 +0000 (+0900) Subject: [title] Fixed stoping query-log when couldn't search in JOB queue X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=fc0c5dc1b54d8de2d5ff812dbaa6521f31521193;p=sdk%2Ftools%2Fsdk-build.git [title] Fixed stoping query-log when couldn't search in JOB queue --- diff --git a/build-cli b/build-cli index 80001d3..901b94e 100755 --- a/build-cli +++ b/build-cli @@ -340,6 +340,7 @@ begin if not log.flock(File::LOCK_EX|File::LOCK_NB) then raise RuntimeError, "The output file is already exist." end + log.sync = true puts "Started query log, writing to the file \"#{output}\"" end @@ -348,6 +349,11 @@ begin next end + if line.eql? "=LOG_ERROR" then + result = false + break + end + log.puts line if not output.nil? and flock.eql? "ON" then log.flock(File::LOCK_UN) diff --git a/src/build_server/BuildServer.rb b/src/build_server/BuildServer.rb index 51ddf60..60b332b 100644 --- a/src/build_server/BuildServer.rb +++ b/src/build_server/BuildServer.rb @@ -788,13 +788,8 @@ class BuildServer 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") @@ -804,30 +799,25 @@ class BuildServer 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 @@ -840,7 +830,13 @@ class BuildServer 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) diff --git a/src/build_server/JobManager.rb b/src/build_server/JobManager.rb index bb93feb..71b98e6 100644 --- a/src/build_server/JobManager.rb +++ b/src/build_server/JobManager.rb @@ -487,7 +487,20 @@ class JobManager return result end - + def search_job (job_id) + (@jobs + @internal_jobs + @reverse_build_jobs).each do |job| + if job.id == job_id then + return job + end + job.sub_jobs.each do |job| + if job.id == job_id then + return job + end + end + end + return nil + end + protected # select the job whith no build-dependency problem # if "check_dep_wait" is true, it will check the build dependency