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

Version Path
flydata-0.7.4 lib/flydata/fluent-plugins/flydata_plugin_ext/transaction_support.rb
flydata-0.7.2.1 lib/flydata/fluent-plugins/flydata_plugin_ext/transaction_support.rb
flydata-0.7.2 lib/flydata/fluent-plugins/flydata_plugin_ext/transaction_support.rb
flydata-0.7.1 lib/flydata/fluent-plugins/flydata_plugin_ext/transaction_support.rb
flydata-0.7.0 lib/flydata/fluent-plugins/flydata_plugin_ext/transaction_support.rb
flydata-0.6.14 lib/flydata/fluent-plugins/flydata_plugin_ext/transaction_support.rb
flydata-0.6.13 lib/flydata/fluent-plugins/flydata_plugin_ext/transaction_support.rb
flydata-0.6.12 lib/flydata/fluent-plugins/flydata_plugin_ext/transaction_support.rb
flydata-0.6.11 lib/flydata/fluent-plugins/flydata_plugin_ext/transaction_support.rb
flydata-0.6.10 lib/flydata/fluent-plugins/flydata_plugin_ext/transaction_support.rb
flydata-0.6.9 lib/flydata/fluent-plugins/flydata_plugin_ext/transaction_support.rb
flydata-0.6.8 lib/flydata/fluent-plugins/flydata_plugin_ext/transaction_support.rb
flydata-0.6.7 lib/flydata/fluent-plugins/flydata_plugin_ext/transaction_support.rb
flydata-0.6.6 lib/flydata/fluent-plugins/flydata_plugin_ext/transaction_support.rb
flydata-0.6.5 lib/flydata/fluent-plugins/flydata_plugin_ext/transaction_support.rb