5 Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
8 Taejun Ha <taejun.ha@samsung.com>
9 Jiil Hyoun <jiil.hyoun@samsung.com>
10 Donghyuk Yang <donghyuk.yang@samsung.com>
11 DongHee Yang <donghee.yang@samsung.com>
13 Licensed under the Apache License, Version 2.0 (the "License");
14 you may not use this file except in compliance with the License.
15 You may obtain a copy of the License at
17 http://www.apache.org/licenses/LICENSE-2.0
19 Unless required by applicable law or agreed to in writing, software
20 distributed under the License is distributed on an "AS IS" BASIS,
21 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
22 See the License for the specific language governing permissions and
23 limitations under the License.
31 $LOAD_PATH.unshift File.dirname(__FILE__)
32 $LOAD_PATH.unshift File.dirname(File.dirname(__FILE__))+"/common"
33 require "BuildServer.rb"
35 require "ScheduledActionHandler.rb"
37 $access_listfile = Mutex.new
39 class JobCleanAction < Action
41 def initialize( time, job_path, list_file, server )
45 @job_id = @job_path.split("/")[-1]
46 @list_file = list_file
52 $access_listfile.synchronize {
53 File.open(@list_file, "a") do |f|
54 f.puts "#{@job_id},#{time.year},#{time.month},#{time.day},#{time.hour},#{time.min},#{time.sec}"
62 @server.log.info "Executing clean action for the job #{@job_id}"
66 @server.log.error e.message
67 @server.log.error e.backtrace.inspect
73 def execute_internal()
75 if File.exist? "#{@job_path}/buildroot" then
76 FileUtils.rm_rf "#{@job_path}/buildroot"
78 if File.exist? "#{@job_path}/temp" then
79 FileUtils.rm_rf "#{@job_path}/temp"
81 if File.exist? "#{@job_path}/external_pkgs" then
82 FileUtils.rm_rf "#{@job_path}/external_pkgs"
85 # remove line for the job
86 $access_listfile.synchronize {
89 if File.exist? @list_file then
90 File.open(@list_file,"r") do |f|
97 # write the line except my job_id
98 File.open(@list_file,"w") do |f|
100 if l.split(",")[0].eql? @job_id then next end
113 def initialize( server )
115 @handler = ScheduledActionHandler.new
116 @list_file = "#{BuildServer::CONFIG_ROOT}/#{@server.id}/clean"
123 list_file2 = "#{BuildServer::CONFIG_ROOT}/#{@server.id}/clean_backup"
124 jobs_path = "#{@server.path}/jobs"
125 if not File.exist? jobs_path then
126 FileUtils.mkdir_p jobs_path
131 if File.exist? @list_file then
132 FileUtils.mv(@list_file,list_file2)
133 File.open(list_file2, "r") do |f|
136 year = l.split(",")[1]
137 month = l.split(",")[2]
138 day = l.split(",")[3]
139 hour = l.split(",")[4]
140 min = l.split(",")[5]
141 sec = l.split(",")[6]
143 # create job and register
144 job_path = "#{jobs_path}/#{id}"
145 time = Time.mktime(year.to_i, month.to_i, day.to_i, hour.to_i, min.to_i, sec.to_i)
146 @server.log.info "Registered clean-action for the job in list : #{id}"
147 @handler.register(JobCleanAction.new(time,job_path,@list_file, @server))
157 Dir.new(jobs_path).entries.each do |id|
159 if id.eql? "." or id.eql? ".." then next end
161 if not clean_list.include? id then
162 job_path = "#{jobs_path}/#{id}"
164 @server.log.info "Registered clean-action for old job : #{id}"
165 @handler.register(JobCleanAction.new(time,job_path,@list_file, @server))
174 # clean after some time
175 def clean_afterwards(job_id)
176 time = Time.now + @server.keep_time
177 job_path = "#{@server.path}/jobs/#{job_id}"
178 @handler.register(JobCleanAction.new(time, job_path, @list_file, @server))
180 @server.log.info "Registered delayed clean-action for the job #{job_id}"
187 job_path = "#{@server.path}/jobs/#{job_id}"
188 @handler.register(JobCleanAction.new(time, job_path, @list_file, @server))
190 @server.log.info "Registered clean-action for the job #{job_id}"