From 62e1f18deb7f27a914065a07f6896b8c482ee642 Mon Sep 17 00:00:00 2001 From: hataejun Date: Thu, 28 Mar 2013 13:10:19 +0900 Subject: [PATCH] [Title] [dibs] register command async [Type] [Module] [Priority] [Jira#] [Redmine#] [Problem] [Cause] [Solution] [TestCase] --- build-cli | 96 ++++++++++++++++---- src/build_server/SocketJobRequestListener.rb | 12 ++- 2 files changed, 86 insertions(+), 22 deletions(-) diff --git a/build-cli b/build-cli index c34682f..7982fa5 100755 --- a/build-cli +++ b/build-cli @@ -198,15 +198,14 @@ begin result = client.read_lines do |line| if line.strip.start_with?("=JOB_START") then job_id = line.strip.split(",")[1] - next elsif line.strip.start_with?("=JOB_STATUS") then data = line.strip.split(",") job_status = data[1] job_error = data[2] - next + else + # print log + puts line end - # print log - puts line end if not result then @@ -237,21 +236,20 @@ begin data = line.strip.split(",") job_status = data[1] job_error = data[2] - next - end - - # print log - category, level, contents = JobLog.parse_log(line) - if level < Log::LV_USER then next end - - if category == "INFO" then - puts "Info: #{contents}" - elsif category == "WARN" then - puts "Warn: #{contents}" - elsif category == "ERROR" then - puts "Error: #{contents}" else - next + # print log + category, level, contents = JobLog.parse_log(line) + if level < Log::LV_USER then next end + + if category == "INFO" then + puts "Info: #{contents}" + elsif category == "WARN" then + puts "Warn: #{contents}" + elsif category == "ERROR" then + puts "Error: #{contents}" + else + next + end end end @@ -400,6 +398,12 @@ begin end when "register" + client = nil + result = false + job_id = nil + job_status = "" + job_error = "" + # check file exist if not File.exist? option[:package] then puts "The file does not exist!.. #{option[:package]}" @@ -443,8 +447,8 @@ begin begin dock = Utils.create_uniq_name() client.send("REGISTER|BINARY|#{File.basename(option[:package])}|#{option[:passwd]}|#{dock}|#{option[:dist]}|#{option[:user]}|#{option[:noreverse]}") - client.read_lines do |line| - if line.eql?("WAITFORUPLOAD") then + result = client.read_lines do |line| + if line.strip.eql?("WAITFORUPLOAD") then # upload thread = Thread.new do begin @@ -458,13 +462,65 @@ begin thread.join client.send("REGISTERCONTINUE") + elsif line.strip.start_with?("=JOB_START") then + job_id = line.strip.split(",")[1] + elsif line.strip.start_with?("=JOB_STATUS") then + data = line.strip.split(",") + job_status = data[1] + job_error = data[2] else + # print log puts line end end + + if not result then + puts "Error: Communication failed! #{client.get_error_msg()}" + elsif job_id.nil? then + puts job_error + result = false + end ensure client.terminate end + + # Query log in case sync + if result then + begin + client = BuildCommClient.create( bs_ip, bs_port, nil, 0 ) + if client.nil? then + puts "Can't access server #{bs_ip}:#{bs_port}" + exit(-1) + end + + client.send "LOG|#{job_id}" + result = client.read_lines do |line| + if line.strip.start_with?("=JOB_STATUS") then + data = line.strip.split(",") + job_status = data[1] + job_error = data[2] + else + # print log + puts line + end + end + + if not result then + puts "ERROR: Can't query log, Communication failed! #{client.get_error_msg()}" + end + + # Check job status + if not job_status.eql? "FINISHED" then + result = false + end + ensure + client.terminate + end + end + + if not result then + exit 1 + end else raise RuntimeError, "input option incorrect : #{option[:cmd]}" end diff --git a/src/build_server/SocketJobRequestListener.rb b/src/build_server/SocketJobRequestListener.rb index a996c37..c8a3e0e 100644 --- a/src/build_server/SocketJobRequestListener.rb +++ b/src/build_server/SocketJobRequestListener.rb @@ -738,6 +738,14 @@ class SocketJobRequestListener BuildCommServer.send_end(req) BuildCommServer.disconnect(req) + BuildCommServer.send(req, "=JOB_START,#{new_job.id}") + BuildCommServer.send(req,"Info: Added new job \"#{new_job.id}\" for #{new_job.os}!") + if not @parent_server.job_log_url.empty? then + BuildCommServer.send(req,"Info: * Log URL : #{@parent_server.job_log_url}/#{new_job.id}/log") + end + + BuildCommServer.send(req,"Info: Above job(s) will be processed asynchronously!") + # add @parent_server.jobmgr.add_job( new_job ) @@ -790,7 +798,7 @@ class SocketJobRequestListener # create new job @log.info "Received a request for uploading binaries : #{filename}" - new_job = create_new_upload_job( prj.name, filename, dock, dist_name, req ) + new_job = create_new_upload_job( prj.name, filename, dock, dist_name ) if new_job.nil? then raise BuildServerException.new("ERR006"), "Register-job #{filename}, #{prj.name}, #{dist_name}" end @@ -1053,7 +1061,7 @@ class SocketJobRequestListener private - def create_new_upload_job( project_name, filename, dock, dist_name, req) + def create_new_upload_job( project_name, filename, dock, dist_name) return @parent_server.prjmgr.get_project(project_name, dist_name).create_new_job(filename, dock) end -- 2.34.1