Changeset 223

Show
Ignore:
Timestamp:
12/07/06 11:02:01 (2 years ago)
Author:
sacha
Message:

some api helpers.
closing transaction adds time and date.
closing transaciton removes temporary state pointer.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • branches/message-handling-refactor-branch/src/hefeweizen_library_transactions.rb

    r212 r223  
    1515      public  
    1616       
    17       def self.instance config, transaction_directory 
     17      def self.instance config 
    1818        if @@instance.nil? then 
    19           @@instance = HefeWeizenTransactionManager.new config, transaction_directory 
     19          @@instance = HefeWeizenTransactionManager.new config 
    2020        end 
    2121         
     
    2929      private  
    3030       
    31       def initialize config, transaction_directory 
     31      def initialize config 
    3232        @config = config 
    33         @transaction_directory = transaction_directory 
     33        @transaction_directory = @config['TRANSACTION_DIR'] 
    3434        @logger = @config['LOGGER'] 
    3535         
     
    135135      end 
    136136 
     137      def open_and_new? 
     138        (is_open? and (@state.name == 'new')) 
     139      end 
     140 
     141 
    137142      def is_open? 
    138143        @type == "OPEN" ? true : false 
     
    162167            cause.payloads.each{ | payload_path | 
    163168              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}" 
    166170              FileUtils.cp(payload_path, target) 
    167171            } 
     
    193197        files_path = files_path.class == String ? [files_path] : files_path 
    194198        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}" 
    196200          file = File.open(file, "w") 
    197201          file << file_path 
     
    206210          files.each{ | file | 
    207211            if FileTest.exists?(file) and FileTest.owned?(file) then 
    208               file_to_delete = File.read(file) 
     212              puts file_to_delete = File.read(file) 
    209213              @logger.debug "Removing file: #{file}" 
    210214              if FileTest.exists?(file_to_delete) and FileTest.owned?(file_to_delete) then 
     
    236240      end 
    237241       
     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 
    238250      # this method closes an open transaction. 
    239251      def close_transaction final_state, comment 
     
    248260          FileUtils.ln_s("states/#{@state.name}", "#{@transaction_path}/current_state", :force => true) 
    249261          FileUtils.touch("#{@transaction_path}/final_state__#{final_state}") 
    250            
    251262          if !comment.nil? then 
    252263            FileUtils.touch("#{@state.full_path}/comment__#{comment.gsub(/ /,"_") }") 
     
    259270          remove_remembered_files_to_remove 
    260271 
     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 
    261278          from = "#{@transaction_path}" 
    262279          to = "#{@base_dir}/closed_transactions/#{@transaction_id}" 
    263280          FileUtils.mv(from, to) 
     281 
     282 
    264283          return true 
    265284        else