Changeset 223
- Timestamp:
- 12/07/06 11:02:01 (2 years ago)
- Files:
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
branches/message-handling-refactor-branch/src/hefeweizen_library_transactions.rb
r212 r223 15 15 public 16 16 17 def self.instance config , transaction_directory17 def self.instance config 18 18 if @@instance.nil? then 19 @@instance = HefeWeizenTransactionManager.new config , transaction_directory19 @@instance = HefeWeizenTransactionManager.new config 20 20 end 21 21 … … 29 29 private 30 30 31 def initialize config , transaction_directory31 def initialize config 32 32 @config = config 33 @transaction_directory = transaction_directory33 @transaction_directory = @config['TRANSACTION_DIR'] 34 34 @logger = @config['LOGGER'] 35 35 … … 135 135 end 136 136 137 def open_and_new? 138 (is_open? and (@state.name == 'new')) 139 end 140 141 137 142 def is_open? 138 143 @type == "OPEN" ? true : false … … 162 167 cause.payloads.each{ | payload_path | 163 168 uuid = HefeWeizen::HefeWeizenLibrary::HefeWeizenUUID.uuid 164 puts payload_path 165 puts target = "#{path}/payload_#{payload_path.gsub(/\//, "@@@@")}_uuid_#{uuid}" 169 target = "#{path}/payload_#{payload_path.gsub(/\//, "@@@@")}_uuid_#{uuid}" 166 170 FileUtils.cp(payload_path, target) 167 171 } … … 193 197 files_path = files_path.class == String ? [files_path] : files_path 194 198 files_path.each{| file_path | 195 file = "#{@transaction_path}/remove_file__#{ file_path.gsub(/\//,"_")}"199 file = "#{@transaction_path}/remove_file__#{Time.now.to_f.to_s}" 196 200 file = File.open(file, "w") 197 201 file << file_path … … 206 210 files.each{ | file | 207 211 if FileTest.exists?(file) and FileTest.owned?(file) then 208 file_to_delete = File.read(file)212 puts file_to_delete = File.read(file) 209 213 @logger.debug "Removing file: #{file}" 210 214 if FileTest.exists?(file_to_delete) and FileTest.owned?(file_to_delete) then … … 236 240 end 237 241 242 def succeed comment 243 return close_transaction "succeeded", comment 244 end 245 246 def fail comment 247 return close_transaction "failed", comment 248 end 249 238 250 # this method closes an open transaction. 239 251 def close_transaction final_state, comment … … 248 260 FileUtils.ln_s("states/#{@state.name}", "#{@transaction_path}/current_state", :force => true) 249 261 FileUtils.touch("#{@transaction_path}/final_state__#{final_state}") 250 251 262 if !comment.nil? then 252 263 FileUtils.touch("#{@state.full_path}/comment__#{comment.gsub(/ /,"_") }") … … 259 270 remove_remembered_files_to_remove 260 271 272 # time and date when the transaction was closed 273 FileUtils.touch("#{@transaction_path}/transaction_closed_date_time__#{Time.now.to_s}") 274 275 # removing temporary state pointer 276 FileUtils.rm("#{@transaction_path}/current_state") 277 261 278 from = "#{@transaction_path}" 262 279 to = "#{@base_dir}/closed_transactions/#{@transaction_id}" 263 280 FileUtils.mv(from, to) 281 282 264 283 return true 265 284 else
