From d853a273939a8e2d4c25a97d2e8dd3dea554a67d Mon Sep 17 00:00:00 2001 From: "jiil.hyoun" Date: Thu, 7 Feb 2013 16:06:53 +0900 Subject: [PATCH] [Title] refectoring cancel job [Type] Enhancement [Module] Toolchain / [Priority] Major [Jira#] [Redmine#] [Problem] [Cause] [Solution] [TestCase] Change-Id: I1f739f8ec5e1b3c9c0f0791a2801109fbaba6c1f --- src/build_server/CommonJob.rb | 31 ++++++++++++------------------- src/build_server/JobManager.rb | 8 ++++++++ src/build_server/MultiBuildJob.rb | 4 +--- 3 files changed, 21 insertions(+), 22 deletions(-) diff --git a/src/build_server/CommonJob.rb b/src/build_server/CommonJob.rb index f27f6ae..92aea5a 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 + attr_accessor :os, :type, :pre_jobs, :user_id, :event, :sub_jobs USER_JOB_PRIORITY = 100 AUTO_JOB_PRIORITY = 0 @@ -176,12 +176,6 @@ class CommonJob #cancel public def cancel() - # kill sub process if exist? - kill_sub_process() - - @sub_jobs.select{|x| x.event == "NONE"}.each do |sub| - sub.event = "CANCEL" - end if not @log.nil? then @log.info( "JOB is canceled by cancel operation !!", Log::LV_USER) end @@ -220,8 +214,8 @@ class CommonJob def lock_event(&block) @event_lock.synchronize do if not @locked then - @locked = true yield if block_given? + @locked = true else raise BuildServerException.new("ERR901"),"JOB ##{@id} alreay in Upload status\n - cancel failed" end @@ -283,6 +277,16 @@ class CommonJob end + def kill_sub_process() + if @sub_pid != 0 then + if not @log.nil? then + @log.info("Killing sub process! id = #{@sub_pid}") + end + Utils.kill_process(@sub_pid) + end + end + + # # PROTECTED METHODS # @@ -292,15 +296,4 @@ class CommonJob def job_main # do nothing end - - - protected - def kill_sub_process() - if @sub_pid != 0 then - if not @log.nil? then - @log.info("Killing sub process! id = #{@sub_pid}") - end - Utils.kill_process(@sub_pid) - end - end end diff --git a/src/build_server/JobManager.rb b/src/build_server/JobManager.rb index e9ac92b..8c4d47e 100644 --- a/src/build_server/JobManager.rb +++ b/src/build_server/JobManager.rb @@ -185,6 +185,7 @@ class JobManager save_job_status(job) Thread.current.exit end + job.check_event if job.status == "INITIALIZING" then job.status = "WAITING" save_job_status(job) @@ -234,6 +235,13 @@ 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 diff --git a/src/build_server/MultiBuildJob.rb b/src/build_server/MultiBuildJob.rb index 99ef88a..b4d899b 100644 --- a/src/build_server/MultiBuildJob.rb +++ b/src/build_server/MultiBuildJob.rb @@ -383,9 +383,7 @@ class MultiBuildJob < CommonJob break end end - - # - sleep 1 + check_event end if stop_status == "ERROR" or stop_status == "CANCELED" then -- 2.34.1