Sha256: 8f0322319852150d114904b38cc02197d7e4ad5ed44b707d387c8819b5cadf25

Contents?: true

Size: 1.48 KB

Versions: 23

Compression:

Stored size: 1.48 KB

Contents

# frozen_string_literal: true

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

      # # Listen public queue to all Janus instance
      #
      # Listen standard queue and sending a block code to thread listen.
      # The default queue is configured in config file.
      #
      # @see file:/config/default.md For more information to config file used.
      class Event < Concurrency
        include Singleton

        NAME_VAR = :publish

        def initialize
          super
          @thread = Thread.new { initialize_thread }
        rescue
          raise Errors::Janus::Event::Initializer
        end

        # Create a thread for execute a block code in a thread
        #
        # @param [Proc] block Block code for execute action when queue
        #   standard 'from-janus' receive a message.This block is sending to
        #   publisher created for this thread.
        #
        # @return [Thread] It's a thread who listen queue and execute action
        def run(&block)
          @thread.join
          Thread.new do
            loop do
              @thread.thread_variable_get(NAME_VAR).listen_events(&block)
            end
          end
        rescue
          raise Errors::Janus::Event::Run
        end

        private

        def transaction_running
          publisher = Rabbit::Listener::From.new(rabbit)
          @thread.thread_variable_set(NAME_VAR, publisher)
        end
      end
    end
  end
end

Version data entries

23 entries across 23 versions & 1 rubygems

Version Path
ruby_rabbitmq_janus-2.7.1 lib/rrj/janus/processus/event.rb
ruby_rabbitmq_janus-2.7.1.pre.274 lib/rrj/janus/processus/event.rb
ruby_rabbitmq_janus-2.7.0.pre.272 lib/rrj/janus/processus/event.rb
ruby_rabbitmq_janus-2.7.0 lib/rrj/janus/processus/event.rb
ruby_rabbitmq_janus-2.7.0.pre.269 lib/rrj/janus/processus/event.rb
ruby_rabbitmq_janus-2.7.0.pre.267 lib/rrj/janus/processus/event.rb
ruby_rabbitmq_janus-2.6.0 lib/rrj/janus/processus/event.rb
ruby_rabbitmq_janus-2.6.0.pre.263 lib/rrj/janus/processus/event.rb
ruby_rabbitmq_janus-2.6.0.pre.261 lib/rrj/janus/processus/event.rb
ruby_rabbitmq_janus-2.6.0.pre.260 lib/rrj/janus/processus/event.rb
ruby_rabbitmq_janus-2.6.0.pre.259 lib/rrj/janus/processus/event.rb
ruby_rabbitmq_janus-2.6.0.pre.258 lib/rrj/janus/processus/event.rb
ruby_rabbitmq_janus-2.6.0.pre.247 lib/rrj/janus/processus/event.rb
ruby_rabbitmq_janus-2.6.0.pre.246 lib/rrj/janus/processus/event.rb
ruby_rabbitmq_janus-2.6.0.pre.244 lib/rrj/janus/processus/event.rb
ruby_rabbitmq_janus-2.6.0.pre.240 lib/rrj/janus/processus/event.rb
ruby_rabbitmq_janus-2.6.0.pre.239 lib/rrj/janus/processus/event.rb
ruby_rabbitmq_janus-2.6.0.pre.238 lib/rrj/janus/processus/event.rb
ruby_rabbitmq_janus-2.6.0.pre.233 lib/rrj/janus/processus/event.rb
ruby_rabbitmq_janus-2.6.0.pre.229 lib/rrj/janus/processus/event.rb