Sha256: 3573e6dd35d30bbd22ce0bcc4fd2551de98da6e030e70db879dd0f84119ef281

Contents?: true

Size: 1.6 KB

Versions: 8

Compression:

Stored size: 1.6 KB

Contents

# frozen_string_literal: true

# :reek:UtilityFunction

module RubyRabbitmqJanus
  module Models
    # Add method for JanusInstance model
    module JanusInstanceConcern
      extend ActiveSupport::Concern

      # Send an action for destroying a session in Janus Gateway instance
      def destroy_before_action
        options = { 'session_id' => session, 'instance' => instance }
        search_initializer(options) do |transaction|
          transaction.publish_message('base::destroy', options)
        end
      end

      # Class methods for JanusInstance model
      module ClassMethods
        # Disable an instance
        def disable(session_id)
          JanusInstance.find_by(session: session_id).set(enable: false)
        end

        # Delete all instance disabled
        def destroys
          JanusInstance.where(enable: false).delete_all
        end

        # Search a record by instance number
        def find_by_instance(instance_search)
          JanusInstance.find_by(instance: instance_search)
        rescue
          false
        end

        # Search a record by session number
        def find_by_session(session_search)
          JanusInstance.find_by(session: session_search)
        rescue
          nil
        end
      end

      private

      def search_initializer(options)
        if File.basename($PROGRAM_NAME) == 'rake'
          ::RRJ.start_transaction(options) do |transaction|
            yield(transaction)
          end
        else
          ::RRJ.start_transaction(true, options) do |transaction|
            yield(transaction)
          end
        end
      end
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
ruby_rabbitmq_janus-2.1.1 lib/rrj/models/concerns/janus_instance_concern.rb
ruby_rabbitmq_janus-2.1.1.pre.139 lib/rrj/models/concerns/janus_instance_concern.rb
ruby_rabbitmq_janus-2.1.0 lib/rrj/models/concerns/janus_instance_concern.rb
ruby_rabbitmq_janus-2.1.0.pre.137 lib/rrj/models/concerns/janus_instance_concern.rb
ruby_rabbitmq_janus-2.1.0.pre.136 lib/rrj/models/concerns/janus_instance_concern.rb
ruby_rabbitmq_janus-2.1.0.pre.135 lib/rrj/models/concerns/janus_instance_concern.rb
ruby_rabbitmq_janus-2.1.0.pre.132 lib/rrj/models/concerns/janus_instance_concern.rb
ruby_rabbitmq_janus-2.1.0.pre.131 lib/rrj/models/concerns/janus_instance_concern.rb