Sha256: c39d754cd617a3c18bd896b33b861ff8aba135f290e3470d614971f4c2d46a33

Contents?: true

Size: 1.39 KB

Versions: 32

Compression:

Stored size: 1.39 KB

Contents

# frozen_string_literal: true

module RubyRabbitmqJanus
  module Tools
    # @author VAILLANT Jeremy <jeremy.vaillant@dazzl.tv>

    # # Manage Janus instance
    class Cluster
      include Singleton

      # Initialize object for managing each instance to Janus
      def initialize
        @current_instance = nil
      end

      # Create session (just one Janus Instance)
      def create_session
        @current_instance = 1
        Models::JanusInstance.create(instance: @current_instance)
      rescue
        raise Errors::Tools::Cluster::CreateSession
      end

      # Restart a thread keepalive for an instance
      def restart_session
        Models::JanusInstance.enabled.each do |ji|
          ji.send(:create_a_session_in_janus_instance)
        end
      rescue
        raise Errors::Tools::Cluster::RestartInstance
      end

      # Specify a name to queue
      def queue_to(instance = nil)
        Tools::Config.instance.options['queues']['standard']['to'] + \
          "-#{instance.blank? ? @current_instance : instance}"
      rescue
        raise Errors::Tools::Cluster::QueueTo
      end

      # Specify a name to admin queue
      def queue_admin_to(instance = nil)
        Tools::Config.instance.options['queues']['admin']['to'] + \
          "-#{instance.blank? ? @current_instance : instance}"
      rescue
        raise Errors::Tools::Cluster::QueueAdminTo
      end
    end
  end
end

Version data entries

32 entries across 32 versions & 1 rubygems

Version Path
ruby_rabbitmq_janus-2.5.1.pre.217 lib/rrj/tools/gem/cluster.rb
ruby_rabbitmq_janus-2.5.1 lib/rrj/tools/gem/cluster.rb
ruby_rabbitmq_janus-2.5.1.pre.215 lib/rrj/tools/gem/cluster.rb
ruby_rabbitmq_janus-2.5.0 lib/rrj/tools/gem/cluster.rb
ruby_rabbitmq_janus-2.5.0.pre.213 lib/rrj/tools/gem/cluster.rb
ruby_rabbitmq_janus-2.5.0.pre.210 lib/rrj/tools/gem/cluster.rb
ruby_rabbitmq_janus-2.5.0.pre.209 lib/rrj/tools/gem/cluster.rb
ruby_rabbitmq_janus-2.4.0.pre.208 lib/rrj/tools/gem/cluster.rb
ruby_rabbitmq_janus-2.3.1.pre.201 lib/rrj/tools/gem/cluster.rb
ruby_rabbitmq_janus-2.3.1.pre.198 lib/rrj/tools/gem/cluster.rb
ruby_rabbitmq_janus-2.3.0.pre.197 lib/rrj/tools/gem/cluster.rb
ruby_rabbitmq_janus-2.3.0.pre.196 lib/rrj/tools/gem/cluster.rb
ruby_rabbitmq_janus-2.3.0 lib/rrj/tools/gem/cluster.rb
ruby_rabbitmq_janus-2.3.0.pre.194 lib/rrj/tools/gem/cluster.rb
ruby_rabbitmq_janus-2.3.0.pre.192 lib/rrj/tools/gem/cluster.rb
ruby_rabbitmq_janus-2.3.0.pre.170 lib/rrj/tools/gem/cluster.rb
ruby_rabbitmq_janus-2.2.2 lib/rrj/tools/gem/cluster.rb
ruby_rabbitmq_janus-2.2.1 lib/rrj/tools/gem/cluster.rb
ruby_rabbitmq_janus-2.2.1.pre.181 lib/rrj/tools/gem/cluster.rb
ruby_rabbitmq_janus-2.2.1.pre.180 lib/rrj/tools/gem/cluster.rb