[title] Fixed stoping query-log when couldn't search in JOB queue
authorSungmin kim <dev.sungmin.kim@samsung.com>
Tue, 2 Apr 2013 11:44:26 +0000 (20:44 +0900)
committerSungmin kim <dev.sungmin.kim@samsung.com>
Tue, 2 Apr 2013 11:44:26 +0000 (20:44 +0900)
build-cli
src/build_server/BuildServer.rb
src/build_server/JobManager.rb

index 80001d322c963222e56968e037020a1c68335147..901b94ec5e98f14b4cf45d90df77c56ffd741412 100755 (executable)
--- 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)
index 51ddf60be712520a90dec586c7ee2e8e95fa2047..60b332bc89699fa36e9cc7d03b48091789b24e12 100644 (file)
@@ -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)
index bb93febdcb76596a0349f37183a6f3c785a9600d..71b98e65617c599196e958f3cd3656b73764483f 100644 (file)
@@ -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