@log.info( "Invoking a thread for building Job #{@id}", Log::LV_USER)
if @status == "ERROR" then return end
@thread = Thread.new {
- # main
- thread_main()
-
- # close
- if not is_sub_job? then
- terminate()
+ begin
+ thread_main()
+ if not is_sub_job? then terminate() end
+ rescue => e
+ @log.error e.message
+ @log.error e.backtrace.inspect
end
}
@log.info( "Invoking a thread for FULL-BUILD Job #{@id}", Log::LV_USER)
if @status == "ERROR" then return end
@thread = Thread.new {
- # main
- thread_main()
-
- # close
- terminate()
+ begin
+ thread_main()
+ terminate()
+ rescue => e
+ @log.error e.message
+ @log.error e.backtrace.inspect
+ end
}
if sync then
def execute
-
# Start to clean job
@server.log.info "Executing clean action for the job #{@job_id}"
+ begin
+ execute_internal()
+ rescue => e
+ @server.log.error e.message
+ @server.log.error e.backtrace.inspect
+ end
+ end
+
+ private
+ def execute_internal()
# remove directories
if File.exist? "#{@job_path}/buildroot" then
FileUtils.rm_rf "#{@job_path}/buildroot"
def initialize_job ( job )
job.status = "INITIALIZING"
Thread.new {
- # init
- if not job.init or job.status == "ERROR" then
- if job.cancel_state == "NONE" then job.status = "ERROR" end
- @parent.log.info "Adding the job \"#{job.id}\" is canceled"
- job.terminate()
- Thread.current.exit
- end
- if job.status != "FINISHED" then
- job.status = "WAITING"
+ begin
+ # init
+ if not job.init or job.status == "ERROR" then
+ if job.cancel_state == "NONE" then job.status = "ERROR" end
+ @parent.log.info "Adding the job \"#{job.id}\" is canceled"
+ job.terminate()
+ Thread.current.exit
+ end
+ if job.status != "FINISHED" then
+ job.status = "WAITING"
+ end
+ @parent.log.info "Checking the job \"#{job.id}\" was finished!"
+ rescue => e
+ @parent.log.error e.message
+ @parent.log.error e.backtrace.inspect
end
- @parent.log.info "Checking the job \"#{job.id}\" was finished!"
}
@parent.log.info "Job \"#{job.id}\" entered INITIALIZING status"
end
job.cancel_state = "WORKING"
@parent.log.info "Creating thread for canceling the job \"#{job.id}\""
Thread.new {
- # thread terminate
- if not job.thread.nil? then
+ begin
#terminate job thread
- job.thread.terminate
- job.thread = nil
- end
+ if not job.thread.nil? then
+ job.thread.terminate
+ job.thread = nil
+ end
- # job cacncel
- job.cancel
+ # job cacncel
+ job.cancel
- # cancel finished
- job.status = "CANCELED"
+ # cancel finished
+ job.status = "CANCELED"
- # call terminate process for job
- job.terminate
+ # call terminate process for job
+ job.terminate
+ rescue => e
+ @parent.log.error e.message
+ @parent.log.error e.backtrace.inspect
+ end
}
end
@log.info( "Invoking a thread for MULTI-BUILD Job #{@id}", Log::LV_USER)
if @status == "ERROR" then return end
@thread = Thread.new {
- # main
- thread_main()
+ begin
+ # main
+ thread_main()
- # close
- terminate()
+ # close
+ terminate()
+ rescue => e
+ @log.error e.message
+ @log.error e.backtrace.inspect
+ end
}
if sync then
def execute
@server.log.info "Executing package-sync action for server \"#{@pkgsvr_url}\""
+
+ begin
+ execute_internal()
+ rescue => e
+ @server.log.error e.message
+ @server.log.error e.backtrace.inspect
+ end
+ end
+
+ private
+ def execute_internal()
# check update
pkgs = check_package_update
@log.info( "Invoking a thread for REGISTER Job #{@id}", Log::LV_USER)
if @status == "ERROR" then return end
@thread = Thread.new {
- # main
- thread_main()
-
- # close
- terminate()
+ begin
+ thread_main()
+ terminate()
+ rescue => e
+ @log.error e.message
+ @log.error e.backtrace.inspect
+ end
}
if sync then
# start listening
def start()
@thread = Thread.new {
- main()
+ # make loop recover when unhandled exception occurred
+ while not @finish_loop
+ begin
+ main()
+ rescue => e
+ @log.error e.message
+ @log.error e.backtrace.inspect
+ end
+ end
}
end
handle_cmd_register( req_line, req )
when "DOWNLOAD"
Thread.new {
- handle_cmd_download( req_line, req )
+ begin
+ handle_cmd_download( req_line, req )
+ rescue => e
+ @log.error "Transfering file failed!"
+ @log.error e.message
+ @log.error e.backtrace.inspect
+ end
}
when "UPLOAD"
Thread.new {
- handle_cmd_upload( req_line, req )
+ begin
+ handle_cmd_upload( req_line, req )
+ rescue => e
+ @log.error "Transfering file failed!"
+ @log.error e.message
+ @log.error e.backtrace.inspect
+ end
}
else
@log.info "Received Unknown REQ: #{req_line}"
dock_num = tok[1].strip
BuildCommServer.send_begin(req)
- begin
- incoming_dir = "#{@parent_server.transport_path}/#{dock_num}"
- if not File.exist? incoming_dir then FileUtils.mkdir_p incoming_dir end
- @comm_server.receive_file( req, incoming_dir )
- rescue => e
- @log.error "Failed to receive file"
- @log.error e.message
- @log.error e.backtrace.inspect
- end
+ incoming_dir = "#{@parent_server.transport_path}/#{dock_num}"
+ if not File.exist? incoming_dir then FileUtils.mkdir_p incoming_dir end
+ @comm_server.receive_file( req, incoming_dir )
BuildCommServer.send_end(req)
end
@log.info "Received a request for download file : #{file_name}"
outgoing_dir = "#{@parent_server.transport_path}/#{dock_num}"
BuildCommServer.send_begin(req)
- begin
- @log.info "Sending requested file...: #{file_name}"
- @comm_server.send_file(req, "#{outgoing_dir}/#{file_name}")
- # remove file if "dock" defined
- if dock_num != "0" then
- @log.info "Removing requested file...: #{file_name}"
- FileUtils.rm_rf "#{outgoing_dir}/#{file_name}"
- if Utils.directory_emtpy?(outgoing_dir) then
- FileUtils.rm_rf "#{outgoing_dir}"
- end
+ @log.info "Sending requested file...: #{file_name}"
+ @comm_server.send_file(req, "#{outgoing_dir}/#{file_name}")
+ # remove file if "dock" defined
+ if dock_num != "0" then
+ @log.info "Removing requested file...: #{file_name}"
+ FileUtils.rm_rf "#{outgoing_dir}/#{file_name}"
+ if Utils.directory_emtpy?(outgoing_dir) then
+ FileUtils.rm_rf "#{outgoing_dir}"
end
- rescue => e
- @log.error "transfer failed"
- @log.error e.message
- @log.error e.backtrace.inspect
end
BuildCommServer.send_end(req)
def execute
-
- # Start to clean job
+ # Start to sync job
@pkgserver.log.info "Executing sync action for the #{@dist_name}"
+ begin
+ execute_internal()
+ rescue => e
+ @pkgserver.log.error e.message
+ @pkgserver.log.error e.backtrace.inspect
+ end
+ end
+
+ private
+ def execute_internal()
# update pkg info
@pkgserver.reload_dist_package