<commit_before># frozen_string_literal: true

module RubyRabbitmqJanus
  module Janus
    module Transactions
      # @author <NAME> <<EMAIL>>
      #
      # This class work with janus and send a series of message
      class Handle < Transaction
        # Initialize a transaction with handle
        #
        # @param [Fixnum] session
        #   Use a session identifier for created message
        def initialize(exclusive, session, handle = 0)
          super(session)
          @exclusive = exclusive
          @handle = handle
        end

        # Opening a long transaction with rabbitmq and is ending closing
        # transaction, so delete exclusive queue
        #
        # @yield Send a message to Janus
        #
        # @return [Fixnum] Sender using in current transaction
        def connect
          rabbit.transaction_short do
            choose_queue
            create_handle if @handle.eql?(0)
            yield
          end
          handle
        end

        # Publish an message in handle
        #
        # @param [String] type Request file used
        # @param [Hash] options Replace/add element in request
        #
        # @return [Janus::Responses::Standard] Response to message sending
        def publish_message(type, options = {})
          optss = opts.merge!(options)
          optss['handle_id'] = @handle if Tools::Cluster.instance.enable
          msg = Janus::Messages::Standard.new(type, optss)
          response = read_response(publisher.publish(msg))
          Janus::Responses::Standard.new(response)
        end

        # Send a message detach
        def detach
          publisher.publish(Janus::Messages::Standard.new('base::detach', opts))
        end

        private

        def create_handle
          Tools::Log.instance.info 'Create an handle'
          opt = { 'session_id' => session }
          msg = Janus::Messages::Standard.new('base::attach', opt)
          Tools::Log.instance.info "Send message attach -- #{@handle}"
          @handle = send_a_message_exclusive { msg }
          Tools::Log.instance.info "Message attach is sending -- #{@handle}"
        end

        def send_a_message_exclusive
          Janus::Responses::Standard.new(read_response_exclusive do
            yield
          end).sender
        end

        def read_response_exclusive
          chan = rabbit.channel
          tmp_publish = Rabbit::Publisher::PublishExclusive.new(chan, '')
          tmp_publish.publish(yield)
        end

        def opts
          { 'session_id' => session, 'handle_id' => @handle }
        end
      end
    end
  end
end
<commit_msg>Add method for delete document in database<commit_after># frozen_string_literal: true

module RubyRabbitmqJanus
  module Janus
    module Transactions
      # @author <NAME> <<EMAIL>>
      #
      # This class work with janus and send a series of message
      class Handle < Transaction
        # Initialize a transaction with handle
        #
        # @param [Fixnum] session
        #   Use a session identifier for created message
        def initialize(exclusive, session, handle = 0)
          super(session)
          @exclusive = exclusive
          @handle = handle
        end

        # Opening a long transaction with rabbitmq and is ending closing
        # transaction, so delete exclusive queue
        #
        # @yield Send a message to Janus
        #
        # @return [Fixnum] Sender using in current transaction
        def connect
          rabbit.transaction_short do
            choose_queue
            create_handle if @handle.eql?(0)
            yield
          end
          handle
        end

        # Publish an message in handle
        #
        # @param [String] type Request file used
        # @param [Hash] options Replace/add element in request
        #
        # @return [Janus::Responses::Standard] Response to message sending
        def publish_message(type, options = {})
          optss = opts.merge!(options)
          optss['handle_id'] = @handle if Tools::Cluster.instance.enable
          msg = Janus::Messages::Standard.new(type, optss)
          response = read_response(publisher.publish(msg))
          Janus::Responses::Standard.new(response)
        end

        # Send a message detach
        def detach
          publisher.publish(Janus::Messages::Standard.new('base::detach', opts))
        end

        # Send a message detach and disable session for deleting in
        # Janus Instance
        def detach_for_deleting
          detach
          Tools::JanusInstance.disable(opts['session_id'])
        end

        private

        def create_handle
          Tools::Log.instance.info 'Create an handle'
          opt = { 'session_id' => session }
          msg = Janus::Messages::Standard.new('base::attach', opt)
          Tools::Log.instance.info "Send message attach -- #{@handle}"
          @handle = send_a_message_exclusive { msg }
          Tools::Log.instance.info "Message attach is sending -- #{@handle}"
        end

        def send_a_message_exclusive
          Janus::Responses::Standard.new(read_response_exclusive do
            yield
          end).sender
        end

        def read_response_exclusive
          chan = rabbit.channel
          tmp_publish = Rabbit::Publisher::PublishExclusive.new(chan, '')
          tmp_publish.publish(yield)
        end

        def opts
          { 'session_id' => session, 'handle_id' => @handle }
        end
      end
    end
  end
end

{'fraction_non_alphanumeric': 0.08222424794895168, 'fraction_numerical': 0.0007292616226071103, 'mean_word_length': 1.975054229934924, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3814392', 'n_tokens_mistral': 1445, 'n_tokens_neox': 1403, 'n_words': 413}