Sha256: c98da037a2101ea60c1c54538913f64258ed5df7fdda1e318a70c91ea0d13390

Contents?: true

Size: 1.46 KB

Versions: 25

Compression:

Stored size: 1.46 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

        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(:publish).listen_events(&block)
            end
          end
        rescue
          raise Errors::Janus::Event::Run
        end

        private

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

Version data entries

25 entries across 25 versions & 1 rubygems

Version Path
ruby_rabbitmq_janus-2.3.1.pre.201 lib/rrj/janus/processus/event.rb
ruby_rabbitmq_janus-2.3.1.pre.198 lib/rrj/janus/processus/event.rb
ruby_rabbitmq_janus-2.3.0.pre.197 lib/rrj/janus/processus/event.rb
ruby_rabbitmq_janus-2.3.0.pre.196 lib/rrj/janus/processus/event.rb
ruby_rabbitmq_janus-2.3.0 lib/rrj/janus/processus/event.rb
ruby_rabbitmq_janus-2.3.0.pre.194 lib/rrj/janus/processus/event.rb
ruby_rabbitmq_janus-2.3.0.pre.192 lib/rrj/janus/processus/event.rb
ruby_rabbitmq_janus-2.3.0.pre.170 lib/rrj/janus/processus/event.rb
ruby_rabbitmq_janus-2.2.2 lib/rrj/janus/processus/event.rb
ruby_rabbitmq_janus-2.2.1 lib/rrj/janus/processus/event.rb
ruby_rabbitmq_janus-2.2.1.pre.181 lib/rrj/janus/processus/event.rb
ruby_rabbitmq_janus-2.2.1.pre.180 lib/rrj/janus/processus/event.rb
ruby_rabbitmq_janus-2.2.0.pre.179 lib/rrj/janus/processus/event.rb
ruby_rabbitmq_janus-2.2.0 lib/rrj/janus/processus/event.rb
ruby_rabbitmq_janus-2.2.0.pre.177 lib/rrj/janus/processus/event.rb
ruby_rabbitmq_janus-2.2.0.pre.173 lib/rrj/janus/processus/event.rb
ruby_rabbitmq_janus-2.2.0.pre.170 lib/rrj/janus/processus/event.rb
ruby_rabbitmq_janus-2.2.0.pre.168 lib/rrj/janus/processus/event.rb
ruby_rabbitmq_janus-2.2.0.pre.167 lib/rrj/janus/processus/event.rb
ruby_rabbitmq_janus-2.2.0.pre.166 lib/rrj/janus/processus/event.rb