[Title] refectoring cancel job
authorjiil.hyoun <jiil.hyoun@samsung.com>
Thu, 7 Feb 2013 07:06:53 +0000 (16:06 +0900)
committerjiil.hyoun <jiil.hyoun@samsung.com>
Thu, 7 Feb 2013 07:06:53 +0000 (16:06 +0900)
[Type] Enhancement
[Module] Toolchain /
[Priority] Major
[Jira#]
[Redmine#]
[Problem]
[Cause]
[Solution]
[TestCase]

Change-Id: I1f739f8ec5e1b3c9c0f0791a2801109fbaba6c1f

src/build_server/CommonJob.rb
src/build_server/JobManager.rb
src/build_server/MultiBuildJob.rb

index f27f6ae875ab7551d06dbe9f37150b4a9b058249..92aea5a131381d7c122a0a92ad8cb727c75d4de1 100644 (file)
@@ -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
index e9ac92bf0cf667324d7b1461a9ed08059248b143..8c4d47ea6f3b7a93b7be39c4a1208197ef184da0 100644 (file)
@@ -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
 
index 99ef88a487fb37641b54c276a420c2ae85ce20fd..b4d899b65f2783c00838378298941db9679a3108 100644 (file)
@@ -383,9 +383,7 @@ class MultiBuildJob < CommonJob
                                        break
                                end
                        end
-
-                       #
-                       sleep 1
+                       check_event
                end
 
                if stop_status == "ERROR" or stop_status == "CANCELED" then