Sha256: ce56802462df0305af42d3337533afa70ec0d681b1247b7ba8ba7470f2fdf63b

Contents?: true

Size: 1.74 KB

Versions: 12

Compression:

Stored size: 1.74 KB

Contents

# frozen_string_literal: true

module RubyRabbitmqJanus
  # Contains all model for this gem
  module Models
    # Configure callback for Janus Instance models
    module JanusInstanceCallbacks
      extend ActiveSupport::Concern

      # Create a session in Janus Instance
      def callback_create_after
        ::Log.debug 'Callback AFTER_VALIDATION'
        create_a_session_in_janus_instance if enable
      end

      # Update a keepalive transaction in Janus Instance
      # Enable or Disable transaction
      def callback_update_after
        ::Log.debug 'Callback AFTER_UPDATE'
        if enable && enable_changed?
          create_a_session_in_janus_instance
        elsif !enable && enable_changed?
          destroy_a_session_in_janus_instance
        end
      end

      # Destroy a session in Janus Instance
      # :reek:UtilityFunction
      def callback_destroy_after
        ::Log.debug 'Callback AFTER_DESTROY'
        # LCO: nothing to do, thread will close session and die
      end

      private

      def create_a_session_in_janus_instance
        RubyRabbitmqJanus::Rabbit::Publisher::JanusInstance.new.publish(message)
      end

      def destroy_a_session_in_janus_instance
        RubyRabbitmqJanus::Rabbit::Publisher::JanusInstance.new.publish(message)
      end

      def keepalive_object
        RubyRabbitmqJanus::Janus::Concurrencies::KeepaliveInitializer
      end

      def keepalive_object_new
        keepalive_object.new(self)
      end

      def keepalive_object_thread
        keepalive_object.thread(thread)
      end

      def info_instance(text)
        ::Log.debug "#{text} in Janus Instance [##{instance}]"
      end

      def message
        {
          id: id.to_s,
          enable: enable
        }
      end
    end
  end
end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
ruby_rabbitmq_janus-2.7.1 lib/rrj/models/concerns/janus_instance_callbacks.rb
ruby_rabbitmq_janus-2.7.1.pre.274 lib/rrj/models/concerns/janus_instance_callbacks.rb
ruby_rabbitmq_janus-2.7.0.pre.272 lib/rrj/models/concerns/janus_instance_callbacks.rb
ruby_rabbitmq_janus-2.7.0 lib/rrj/models/concerns/janus_instance_callbacks.rb
ruby_rabbitmq_janus-2.7.0.pre.269 lib/rrj/models/concerns/janus_instance_callbacks.rb
ruby_rabbitmq_janus-2.7.0.pre.267 lib/rrj/models/concerns/janus_instance_callbacks.rb
ruby_rabbitmq_janus-2.6.0 lib/rrj/models/concerns/janus_instance_callbacks.rb
ruby_rabbitmq_janus-2.6.0.pre.263 lib/rrj/models/concerns/janus_instance_callbacks.rb
ruby_rabbitmq_janus-2.6.0.pre.261 lib/rrj/models/concerns/janus_instance_callbacks.rb
ruby_rabbitmq_janus-2.6.0.pre.260 lib/rrj/models/concerns/janus_instance_callbacks.rb
ruby_rabbitmq_janus-2.6.0.pre.259 lib/rrj/models/concerns/janus_instance_callbacks.rb
ruby_rabbitmq_janus-2.6.0.pre.258 lib/rrj/models/concerns/janus_instance_callbacks.rb