From: donghee yang Date: Tue, 26 Mar 2013 08:15:06 +0000 (+0900) Subject: [Title] Fixed a bug that "CANCEL" is not applied immediately X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=a40b02e6cf8842438c796aca13aac56cc6d72c41;p=sdk%2Ftools%2Fsdk-build.git [Title] Fixed a bug that "CANCEL" is not applied immediately --- diff --git a/src/build_server/BuildJob.rb b/src/build_server/BuildJob.rb index c44f939..a440e9b 100644 --- a/src/build_server/BuildJob.rb +++ b/src/build_server/BuildJob.rb @@ -45,7 +45,7 @@ require "CommonJob.rb" class BuildJob < CommonJob attr_accessor :pkginfo, :source_path - attr_accessor :pkgsvr_client, :thread + attr_accessor :pkgsvr_client # attr_accessor :rev_fail_projects, :rev_success_jobs # attr_accessor :pending_ancestor attr_accessor :no_reverse @@ -75,7 +75,6 @@ class BuildJob < CommonJob # this item will be initialized on pre-verify @pkginfo = nil @pkgsvr_client = nil - @thread = nil @log = nil @parent = nil # for job hierachy @@ -186,7 +185,7 @@ class BuildJob < CommonJob kill_sub_process() # cancel all its sub jobs - @sub_jobs.select{|x| x.event == "NONE"}.each do |sub| + @sub_jobs.select{|x| x.event == "NONE" and x.status != "FINISHED" and x.status != "ERROR" and x.status != "CANCELED" }.each do |sub| sub.event = "CANCEL" end @@ -197,13 +196,7 @@ class BuildJob < CommonJob end end - # cancel log print - if not @log.nil? then - @log.info( "JOB is canceled by cancel operation !!", Log::LV_USER) - end - - case @status - when "REMOTE_WORKING" then + if @status == "REMOTE_WORKING" then client = BuildCommClient.create( @remote_server.ip, @remote_server.port, @log ) if not client.nil? then client.send "CANCEL|#{@remote_id}|#{self.get_project.passwd}|admin@user" @@ -217,40 +210,14 @@ class BuildJob < CommonJob end client.terminate end - #when "PENDING" then - # if @pending_ancestor.nil? then - # #resolve pending job - # pending_descendants = @server.jobmgr.jobs.select do |j| - # (not j.pending_ancestor.nil?) and "#{j.pending_ancestor.id}" == "#{@id}" - # end - # pending_descendants.each do |pd| - # pd.cancel_state = "INIT" - # end - # else - # # remove myself from success job if exist - # # and add myself into rev_fail_project list if not exist - # @pending_ancestor.remove_rev_success_job(self) - # @pending_ancestor.add_rev_fail_project( @project, @os ) - - # # remove the project that depends on me if exist - # # and add it into rev_fail_project list if not exist - # p_sub_jobs = @server.jobmgr.jobs.select do |j| - # ( not j.pending_ancestor.nil? and - # "#{j.pending_ancestor.id}" == "#{@pending_ancestor.id}" and - # j.is_build_dependent_project(@project, @os) ) - # end - # p_sub_jobs.each do |d| - # @pending_ancestor.remove_rev_success_job(d) - # @pending_ancestor.add_rev_fail_project( d.get_project, d.os ) - - # if not d.thread.nil? then d.thread.terminate end - # d.status = "WAITING" - # end - # end - when "WORKING", "WAITING" , "INITIALIZING" , "JUST_CREATED" then - #just log - else # ERROR | FINISHED | RESOLVED - #do noting + end + + # wait for job thread to finish + @thread.join if not @thread.nil? + + # cancel log print + if not @log.nil? then + @log.info( "JOB is canceled by cancel operation !!", Log::LV_USER) end end diff --git a/src/build_server/CommonJob.rb b/src/build_server/CommonJob.rb index a352271..eeb6a64 100644 --- a/src/build_server/CommonJob.rb +++ b/src/build_server/CommonJob.rb @@ -35,7 +35,7 @@ require "utils.rb" class CommonJob attr_accessor :id, :server, :log, :status, :priority - attr_accessor :os, :type, :pre_jobs, :user_id, :event, :sub_jobs + attr_accessor :os, :type, :pre_jobs, :user_id, :event, :sub_jobs, :thread USER_JOB_PRIORITY = 100 AUTO_JOB_PRIORITY = 0 @@ -61,6 +61,7 @@ class CommonJob @start_time = Time.now @end_time = nil + @thread = nil @sub_pid = 0 end @@ -172,6 +173,14 @@ class CommonJob #cancel public def cancel() + kill_sub_process + + @sub_jobs.select{|x| x.event == "NONE" and x.status != "FINISHED" and x.status != "ERROR" and x.status != "CANCELED" }.each do |sub| + sub.event = "CANCEL" + end + # wait for job thread to finish + @thread.join if not @thread.nil? + if not @log.nil? then @log.info( "JOB is canceled by cancel operation !!", Log::LV_USER) end diff --git a/src/build_server/JobManager.rb b/src/build_server/JobManager.rb index f8d890a..b85e882 100644 --- a/src/build_server/JobManager.rb +++ b/src/build_server/JobManager.rb @@ -217,14 +217,7 @@ class JobManager @server.log.info "Creating thread for canceling the job \"#{job.id}\"" Thread.new do begin - job.kill_sub_process - - job.sub_jobs.select{|x| x.event == "NONE" and x.status != "FINISHED" and x.status != "ERROR" and x.status != "CANCELED" }.each do |sub| - sub.event = "CANCEL" - end - job.thread.join if not job.thread.nil? - - # job cacncel + # job cancel job.cancel # cancel finished diff --git a/src/build_server/MultiBuildJob.rb b/src/build_server/MultiBuildJob.rb index 07a2697..26b9c39 100644 --- a/src/build_server/MultiBuildJob.rb +++ b/src/build_server/MultiBuildJob.rb @@ -43,7 +43,7 @@ require "CommonJob.rb" class MultiBuildJob < CommonJob attr_accessor :source_path - attr_accessor :pkgsvr_client, :thread + attr_accessor :pkgsvr_client # initialize def initialize (server) diff --git a/src/build_server/RegisterPackageJob.rb b/src/build_server/RegisterPackageJob.rb index 7045466..3ef38d1 100644 --- a/src/build_server/RegisterPackageJob.rb +++ b/src/build_server/RegisterPackageJob.rb @@ -43,7 +43,7 @@ require "CommonJob.rb" class RegisterPackageJob < CommonJob attr_accessor :source_path - attr_accessor :pkgsvr_client, :thread, :pkg_type + attr_accessor :pkgsvr_client, :pkg_type attr_accessor :pkg_name, :pkginfo attr_accessor :no_reverse @@ -233,14 +233,6 @@ class RegisterPackageJob < CommonJob end - #cancel - def cancel() - if not @log.nil? then - @log.info( "JOB is canceled by cancel operation !!", Log::LV_USER) - end - end - - # check building is possible def can_be_built_on?(host_os) return true diff --git a/test/build-server.basic1/build-cli-01.testcase b/test/build-server.basic1/build-cli-01.testcase index 7602874..d1133e3 100644 --- a/test/build-server.basic1/build-cli-01.testcase +++ b/test/build-server.basic1/build-cli-01.testcase @@ -8,36 +8,35 @@ Requiest service to build-server command-line tool. Usage: build-cli [OPTS] or build-cli (-h|-v) Subcommands: -build Build and create package. -query Query information about build-server. -query-system Query system information about build-server. -query-project Query project information about build-server. -query-job Query job information about build-server. -query-log Query log contents about job in build-server. -cancel Cancel a building project. -register Register the package to the build-server. + build Build and create package. + query Query information about build-server. + query-system Query system information about build-server. + query-project Query project information about build-server. + query-job Query job information about build-server. + query-log Query log contents about job in build-server. + cancel Cancel a building project. + register Register the package to the build-server. Subcommand usage: -build-cli build -N -d [-o ] [-w ] [--async] [-D ] [-U user-email] [-V] -build-cli query -d -build-cli query-system -d -build-cli query-project -d -build-cli query-job -d -build-cli query-log -d -j -build-cli cancel -j -d [-w ] -build-cli register -P -d [-t ] [-w ] [-D ] [-U user-email] + build-cli build -N -d [-o ] [-w ] [--async] [-D ] [-U user-email] + build-cli query -d + build-cli query-system -d + build-cli query-project -d + build-cli query-job -d + build-cli query-log -d -j + build-cli cancel -j -d [-w ] [-U user-email] + build-cli register -P -d [-t ] [-w ] [-D ] [-U user-email] Options: --N, --project project name --d, --address build server address: 127.0.0.1:2224 --o, --os target operating system: ubuntu-32/ubuntu-64/windows-32/windows-64/macos-64 ---async asynchronous job --j, --job job number --w, --passwd password for managing project --P, --pkg package file path --D, --dist distribution name --t, --ftp ftp server url: ftp://dibsftp:dibsftp@127.0.0.1 --U, --user user email infomation --V, --verbose verbose mode --h, --help display help --v, --version display version + -N, --project project name + -d, --address build server address: 127.0.0.1:2224 + -o, --os target operating system: ubuntu-32/ubuntu-64/windows-32/windows-64/macos-64 + --async asynchronous job + -j, --job job number + -w, --passwd password for managing project + -P, --pkg package file path + -D, --dist distribution name + -t, --ftp ftp server url: ftp://dibsftp:dibsftp@127.0.0.1 + -U, --user user email infomation + -h, --help display help + -v, --version display version