Sha256: 50ed1f139b7bd750e1678ff11f1b7b83eb89e16436fa91bc5916e22c6b89f303
Contents?: true
Size: 1.32 KB
Versions: 15
Compression:
Stored size: 1.32 KB
Contents
module Fluent class TransactionContext def set_transaction_broken @transaction_broken = true end def transaction_broken? @transaction_broken == true end end # Transaction support # This module is expected to be prepended module TransactionSupport def self.included(base) raise "This module is expected to be prepended" end #def self.prepended(base) #end def configure(conf) @lock_file = Flydata::FLYDATA_LOCK super end def start if File.exists?(@lock_file) $log.error "Previous process was terminated abnormally. To start, remove the lock file after checking data integrity." @abort = true Process.kill(:TERM, Process.ppid) return end super end def process_aborted? instance_variable_defined? :@abort end def do_transaction transaction_context =TransactionContext.new File.open(@lock_file, "w") {|f| f.write(Process.pid)} begin yield(transaction_context) ensure # leave the lock file when a transaction is broken if !transaction_context.transaction_broken? && File.exists?(@lock_file) && Process.pid == File.open(@lock_file, "r") {|f| f.read}.to_i File.delete(@lock_file) end end end end end
Version data entries
15 entries across 15 versions & 1 rubygems