Sha256: 2b68b85a2478b53ed071ef768dab9d0c40b55e0dff3c3632fd8f76873b9d8ef6

Contents?: true

Size: 1.8 KB

Versions: 11

Compression:

Stored size: 1.8 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
        Tools::Log.instance.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
        Tools::Log.instance.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
        Tools::Log.instance.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)
        Tools::Log.instance.debug "#{text} in Janus Instance [##{instance}]"
      end

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

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
ruby_rabbitmq_janus-2.6.0.pre.247 lib/rrj/models/concerns/janus_instance_callbacks.rb
ruby_rabbitmq_janus-2.6.0.pre.246 lib/rrj/models/concerns/janus_instance_callbacks.rb
ruby_rabbitmq_janus-2.6.0.pre.244 lib/rrj/models/concerns/janus_instance_callbacks.rb
ruby_rabbitmq_janus-2.6.0.pre.240 lib/rrj/models/concerns/janus_instance_callbacks.rb
ruby_rabbitmq_janus-2.6.0.pre.239 lib/rrj/models/concerns/janus_instance_callbacks.rb
ruby_rabbitmq_janus-2.6.0.pre.238 lib/rrj/models/concerns/janus_instance_callbacks.rb
ruby_rabbitmq_janus-2.6.0.pre.233 lib/rrj/models/concerns/janus_instance_callbacks.rb
ruby_rabbitmq_janus-2.6.0.pre.229 lib/rrj/models/concerns/janus_instance_callbacks.rb
ruby_rabbitmq_janus-2.6.0.pre.228 lib/rrj/models/concerns/janus_instance_callbacks.rb
ruby_rabbitmq_janus-2.6.0.pre.227 lib/rrj/models/concerns/janus_instance_callbacks.rb
ruby_rabbitmq_janus-2.6.0.pre.226 lib/rrj/models/concerns/janus_instance_callbacks.rb