ruby_rabbitmq_janus 3.0.0.pre.366 → 3.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (34) hide show
  1. checksums.yaml +4 -4
  2. data/Rakefile +1 -2
  3. data/lib/generators/ruby_rabbitmq_janus/migration_generator.rb +2 -0
  4. data/lib/rrj/errors/error.rb +1 -1
  5. data/lib/rrj/janus/responses/admin.rb +13 -9
  6. data/lib/rrj/janus/responses/error.rb +0 -2
  7. data/lib/rrj/janus/responses/rspec.rb +2 -0
  8. data/lib/rrj/janus/responses/standard.rb +1 -0
  9. data/lib/rrj/janus/transactions/handle.rb +2 -0
  10. data/lib/rrj/janus/transactions/rspec.rb +2 -0
  11. data/lib/rrj/janus/transactions/session.rb +1 -0
  12. data/lib/rrj/models/active_record.rb +3 -0
  13. data/lib/rrj/process/concurrency.rb +7 -2
  14. data/lib/rrj/process/thread_runner_concern.rb +1 -1
  15. data/lib/rrj/rabbit/base_event.rb +2 -2
  16. data/lib/rrj/rabbit/connect.rb +21 -4
  17. data/lib/rrj/rabbit/publisher/non_exclusive.rb +3 -0
  18. data/lib/rrj/rspec.rb +5 -0
  19. data/lib/rrj/task.rb +2 -0
  20. data/lib/rrj/tools/gem/config/gem.rb +1 -1
  21. data/lib/rrj/tools/gem/logger.rb +1 -2
  22. data/lib/rrj/tools/gem/requests.rb +2 -2
  23. data/spec/ruby_rabbitmq_janus/janus/responses/response_spec.rb +1 -1
  24. data/spec/ruby_rabbitmq_janus/rabbit/listener/from_spec.rb +1 -0
  25. data/spec/ruby_rabbitmq_janus/rabbit/publisher/admin_spec.rb +1 -0
  26. data/spec/ruby_rabbitmq_janus/rabbit/publisher/exclusive_spec.rb +4 -3
  27. data/spec/ruby_rabbitmq_janus/rabbit/publisher/non_exclusive_spec.rb +4 -4
  28. data/spec/ruby_rabbitmq_janus/tools/replaces/admin_spec.rb +2 -2
  29. data/spec/ruby_rabbitmq_janus/tools/replaces/handle_spec.rb +1 -1
  30. data/spec/ruby_rabbitmq_janus/tools/type_spec.rb +1 -1
  31. data/spec/spec_helper.rb +4 -2
  32. data/spec/support/examples_thread.rb +3 -3
  33. data/tmp/coverage/index.html +2180 -1994
  34. metadata +9 -9
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 83b84d69f38b85260b7a3dfaab6e20582ebe1677de611a1fdaa9dad0524d69a6
4
- data.tar.gz: f8792bdb6808853b7861f5b45b28503471a80ea85fc1b48c125c7dbf6233dee0
3
+ metadata.gz: 641ef9e4c094b6d58e1e990485a6706ba618b007eb005c35e40f0767d6c0ae27
4
+ data.tar.gz: d23f4c37684be9cd9b2a2ef68067963e2f1b4527a8f4cd0414a8d4cf92962f2b
5
5
  SHA512:
6
- metadata.gz: bb76a82bcdb166ed7cece2ac83f8d3c35c662ea3ae1470e871af24170c0c49b0e63d15a6e847c8b2ad53c780dd9d88246a0b8cf455e94c8ad7f5ad5719eeff92
7
- data.tar.gz: 7e1d00d5a99043e9e5dc8efcc82ce61fa4d5320cdcc4191d332c79c81818e974d9defb789c702a2d2ca752b0d429e5910a699775c4fb4e92b09e2a47247a528a
6
+ metadata.gz: 0f4b66c8f33a715816f53fc33e7d4939586f0aebd8b9745217220dbcab70519a22097e886fca5cdbc30f94b4d80be622bf6ece39a0a921bea06b9b6fe8b1cd86
7
+ data.tar.gz: 5a001a600bfc39897daa0c02cc5b8e1939b6e91265e2f527303f210685c2da171b3a9915cc4511aa5f1f51cbd48c3fff745c2cf22811165e96c65ec702168484
data/Rakefile CHANGED
@@ -4,8 +4,7 @@ require 'bundler/gem_tasks'
4
4
  require 'rspec/core/rake_task'
5
5
 
6
6
  # Exclude all spec with type :thread
7
- RSpec::Core::RakeTask.new(:spec) do |_t|
8
- end
7
+ RSpec::Core::RakeTask.new(:spec)
9
8
 
10
9
  # Exclude all spec with type :thread
11
10
  RSpec::Core::RakeTask.new(:classic) do |t|
@@ -16,11 +16,13 @@ module RubyRabbitmqJanus
16
16
 
17
17
  source_root File.expand_path('templates', __dir__)
18
18
 
19
+ # Prepare files for migration.
19
20
  def install
20
21
  migration_template 'migration.rb',
21
22
  'db/migrate/create_ruby_rabbitmq_janus_tables.rb'
22
23
  end
23
24
 
25
+ # Determines the version number of the next migration.
24
26
  def self.next_migration_number(dirname)
25
27
  ActiveRecord::Generators::Base.next_migration_number(dirname)
26
28
  end
@@ -20,7 +20,7 @@ module RubyRabbitmqJanus
20
20
 
21
21
  def write_error(message, level = :unknown)
22
22
  if defined?(::Log)
23
- ::Log.send(level.class.eql?(Symbol) ? level : int_to_level(level),
23
+ ::Log.send(level.instance_of?(Symbol) ? level : int_to_level(level),
24
24
  message)
25
25
  else
26
26
  p "#{level}, #{message}"
@@ -7,55 +7,59 @@ module RubyRabbitmqJanus
7
7
  #
8
8
  # @see Example request response https://janus.conf.meetecho.com/docs/admin.html
9
9
  class Admin < Standard
10
- # List of sessions running in Janus Instance.
11
- #
12
- # @return [Array] List of sessions
10
+ # @return [Array] List of sessions running in Janus Instance.
13
11
  def sessions
14
12
  read_data(__method__.to_s)
15
13
  end
16
14
 
17
- # List of handles running in one session in Janus Instance.
18
- #
19
- # @return [Array] List of handles
15
+ # @return [Array] List of handles running
16
+ # in one session in Janus Instance.
20
17
  def handles
21
18
  read_data(__method__.to_s)
22
19
  end
23
20
 
24
- # Info to session or handle in Janus Instance
25
- #
26
- # @return [Hash] Information to session/handle
21
+ # @return [Hash] Information to session/handle in Janus Instance.
27
22
  def info
28
23
  read_data(__method__.to_s)
29
24
  end
30
25
 
26
+ # @return [Boolean] Information status to debug mode for libnice.
31
27
  def libnice_debug
32
28
  read_data(__method__.to_s)
33
29
  end
34
30
 
31
+ # @return [Boolean] Information status to debug mode
32
+ # in Janus Intance on the fly.
35
33
  def locking_debug
36
34
  read_data(__method__.to_s)
37
35
  end
38
36
 
37
+ # @return [Boolean] Information about color in log messages.
39
38
  def log_colors
40
39
  read_data(__method__.to_s)
41
40
  end
42
41
 
42
+ # @return [Integer] Level to debug mode to Janus Instance.
43
43
  def level
44
44
  read_data(__method__.to_s)
45
45
  end
46
46
 
47
+ # @return [Boolean] Status to timestampping for log messages.
47
48
  def log_timestamps
48
49
  read_data(__method__.to_s)
49
50
  end
50
51
 
52
+ # @return [Integer] Level to max nack queue configured.
51
53
  def max_nack_queue
52
54
  read_data(__method__.to_s)
53
55
  end
54
56
 
57
+ # @return [Integer] No-media timer property.
55
58
  def no_media_timer
56
59
  read_data(__method__.to_s)
57
60
  end
58
61
 
62
+ # @return [Integer] Timeout for session.
59
63
  def timeout
60
64
  read_data(__method__.to_s)
61
65
  end
@@ -143,11 +143,9 @@ module RubyRabbitmqJanus
143
143
 
144
144
  def respond_to_missing?(name, include_private); end
145
145
 
146
- # rubocop:disable Style/MethodMissingSuper
147
146
  def method_missing(_method, request)
148
147
  default_error(request)
149
148
  end
150
- # rubocop:enable Style/MethodMissingSuper
151
149
 
152
150
  def default_error(request)
153
151
  raise RubyRabbitmqJanus::Errors::Janus::Responses::Nok, request
@@ -7,6 +7,8 @@ module RubyRabbitmqJanus
7
7
  module Responses
8
8
  # Response for RSpec initializer
9
9
  class RSpec
10
+ # Constructor to RSpec response.
11
+ # Create a fake response for testing library.
10
12
  def initialize(type)
11
13
  path = RubyRabbitmqJanus::Tools::Config.instance.rspec_response
12
14
  @json = File.join(Dir.pwd,
@@ -18,6 +18,7 @@ module RubyRabbitmqJanus
18
18
  data_id
19
19
  end
20
20
 
21
+ # Read value created by janus for session/handle message
21
22
  def sender
22
23
  raise_data
23
24
 
@@ -70,11 +70,13 @@ module RubyRabbitmqJanus
70
70
  @handle = send_a_message_exclusive { msg }
71
71
  end
72
72
 
73
+ # rubocop:disable Style/ExplicitBlockArgument
73
74
  def send_a_message_exclusive
74
75
  Janus::Responses::Standard.new(read_response_exclusive do
75
76
  yield
76
77
  end).sender
77
78
  end
79
+ # rubocop:enable Style/ExplicitBlockArgument
78
80
 
79
81
  def read_response_exclusive
80
82
  chan = rabbit.channel
@@ -4,6 +4,8 @@ module RubyRabbitmqJanus
4
4
  module Janus
5
5
  module Transactions
6
6
  # Transaction for RSpec initializer
7
+ # @!attribute [r] response
8
+ # Given a Janus response
7
9
  class RSpec
8
10
  attr_reader :response
9
11
 
@@ -28,6 +28,7 @@ module RubyRabbitmqJanus
28
28
  end
29
29
  end
30
30
 
31
+ # Publish a message to "standard" RabbitMQ queue.
31
32
  def publish_message(type, options = {})
32
33
  msg = Janus::Messages::Standard.new(type, opts.merge!(options))
33
34
  response = read_response(publisher.publish(msg))
@@ -31,9 +31,12 @@ module RubyRabbitmqJanus
31
31
  # @param attributes [Array] List to attribute to delete in document
32
32
  #
33
33
  # @return [Hash] Current model
34
+ #
35
+ # rubocop:disable Style/HashTransformValues
34
36
  def unset(attributes)
35
37
  Hash[attributes.map { |key, _value| [key, nil] }]
36
38
  end
39
+ # rubocop:enable Style/HashTransformValues
37
40
  end
38
41
  end
39
42
  end
@@ -27,13 +27,18 @@ module RubyRabbitmqJanus
27
27
  def initialize_thread
28
28
  @rabbit.transaction_long { transaction_running }
29
29
  rescue Interrupt
30
+ ::Log.warn "This process has been interupted #{class_name}"
30
31
  ::Log.warn \
31
- "Close a connection with RabbitMQ instance for #{self.class.name}"
32
+ "Close a connection with RabbitMQ instance for #{class_name}"
32
33
  @rabbit.close
33
34
  end
34
35
 
35
36
  def info_thread
36
- "Create an thread -- #{self.class.name}"
37
+ "Create an thread -- #{class_name}"
38
+ end
39
+
40
+ def class_name
41
+ self.class.name
37
42
  end
38
43
  end
39
44
  end
@@ -31,7 +31,7 @@ module RubyRabbitmqJanus
31
31
  #
32
32
  # @return [Thread] It's a thread who listen queue and execute action
33
33
  def run(&block)
34
- raise_nil_block unless block_given?
34
+ raise_nil_block unless block
35
35
 
36
36
  @thread.join
37
37
  Thread.new do
@@ -10,9 +10,9 @@ module RubyRabbitmqJanus
10
10
  # # Parent class for all publisher
11
11
  # This element send and read a message in rabbitmq Queue
12
12
  #
13
- # @!attribute [r] response
13
+ # @!attribute [r] responses
14
14
  # @return [RubyRabbitmqJanus::Janus::Responses::Response]
15
- # Given a Janus response
15
+ # Given an array of Janus response
16
16
  #
17
17
  # @abstract Publish message in RabbitMQ
18
18
  class BaseEvent
@@ -14,10 +14,17 @@ module RubyRabbitmqJanus
14
14
  end
15
15
 
16
16
  # Create an transaction with rabbitmq and close after response is received
17
- def transaction_short
18
- raise Errors::Rabbit::Connect::MissingAction unless block_given?
17
+ def transaction_short(&block)
18
+ raise Errors::Rabbit::Connect::MissingAction unless block
19
+
20
+ response = nil
19
21
 
20
- response = transaction_long { yield }
22
+ Timeout.timeout(5) do
23
+ response = transaction_long(&block)
24
+ end
25
+ rescue Timeout::Error
26
+ ::Log.error 'The "Short transaction" have raised Timeout exception.'
27
+ ensure
21
28
  close
22
29
  response
23
30
  end
@@ -30,6 +37,8 @@ module RubyRabbitmqJanus
30
37
  start
31
38
  yield
32
39
  end
40
+ rescue Timeout::Error
41
+ ::Log.error 'The "Long transaction" have raised Timeout exception.'
33
42
  end
34
43
 
35
44
  # Opening a connection with RabbitMQ
@@ -50,7 +59,15 @@ module RubyRabbitmqJanus
50
59
  private
51
60
 
52
61
  def bunny_conf
53
- Tools::Config.instance.server_settings.merge(connection_timeout: 5)
62
+ Tools::Config.instance.server_settings.merge(bunny_conf_static)
63
+ end
64
+
65
+ def bunny_conf_static
66
+ {
67
+ connection_timeout: 5,
68
+ connection_name: "[#{rand(999)}] backend",
69
+ recover_from_connection_close: false
70
+ }
54
71
  end
55
72
  end
56
73
  end
@@ -17,9 +17,12 @@ module RubyRabbitmqJanus
17
17
  # Send an message to queue
18
18
  #
19
19
  # @param [String] request JSON request sending to rabbitmq queue
20
+ #
21
+ # rubocop:disable Lint/UselessMethodDefinition
20
22
  def publish(request)
21
23
  super(request)
22
24
  end
25
+ # rubocop:enable Lint/UselessMethodDefinition
23
26
  end
24
27
  end
25
28
  end
data/lib/rrj/rspec.rb CHANGED
@@ -9,20 +9,25 @@ module RubyRabbitmqJanus
9
9
  #
10
10
  # Initializer to use with RSpec execution
11
11
  class RRJRSpec < RRJTaskAdmin
12
+ # rubocop:disable Lint/MissingSuper
12
13
  def initialize
13
14
  RubyRabbitmqJanus::Tools::Config.instance
14
15
  end
16
+ # rubocop:enable Lint/MissingSuper
15
17
 
18
+ # @see RubyRabbitmqJanus::RRJ::session_endpoint_public
16
19
  def session_endpoint_public(_options)
17
20
  yield(RubyRabbitmqJanus::Janus::Transactions::RSpec.new)
18
21
  end
19
22
 
23
+ # @see RubyRabbitmqJanus::RRJ::session_endpoint_private
20
24
  def handle_endpoint_public(_options)
21
25
  transaction = RubyRabbitmqJanus::Janus::Transactions::RSpec.new
22
26
  yield(transaction)
23
27
  transaction.response
24
28
  end
25
29
 
30
+ # @see RubyRabbitmqJanus::RRJAdmin::admin_endpoint
26
31
  def admin_endpoint(_options)
27
32
  yield(RubyRabbitmqJanus::Janus::Transactions::RSpec.new)
28
33
  end
data/lib/rrj/task.rb CHANGED
@@ -9,10 +9,12 @@ module RubyRabbitmqJanus
9
9
  #
10
10
  # This class is used with rake task.
11
11
  class RRJTask < RRJ
12
+ # rubocop:disable Lint/MissingSuper
12
13
  def initialize
13
14
  Tools::Config.instance
14
15
  Tools::Requests.instance
15
16
  end
17
+ # rubocop:enable Lint/MissingSuper
16
18
 
17
19
  # Create a transaction between Apps and Janus in queue private
18
20
  #
@@ -12,7 +12,7 @@ module RubyRabbitmqJanus
12
12
  module ConfigGem
13
13
  # @return [Boolean] Read option file for a janus cluster section
14
14
  def cluster
15
- @options['gem']['cluster']['enabled'].to_s.match?('true') ? true : false
15
+ @options['gem']['cluster']['enabled'].to_s.match?('true')
16
16
  end
17
17
 
18
18
  # @return [Symbol] read configuration for log level used in this gem
@@ -41,7 +41,6 @@ module RubyRabbitmqJanus
41
41
  # Choose type logger used in application instance
42
42
  def self.initialize_logger
43
43
  case @config.log_type
44
- when :stdout then logger_stdout
45
44
  when :file then logger_file
46
45
  when :remote then logger_remote
47
46
  else
@@ -51,7 +50,7 @@ module RubyRabbitmqJanus
51
50
 
52
51
  # Configure logger with output SDTOUT
53
52
  def self.logger_stdout
54
- ::Logger.new(STDOUT)
53
+ ::Logger.new($stdout)
55
54
  end
56
55
 
57
56
  # Configure logger with output file
@@ -32,9 +32,9 @@ module RubyRabbitmqJanus
32
32
  def each_folder(subfolder)
33
33
  Dir[File.join(PATH_REQUEST + subfolder, '*')].count do |file|
34
34
  if File.file?(file)
35
- read_folder(subfolder.gsub('/', '::') + '::', file)
35
+ read_folder("#{subfolder.gsub('/', '::')}::", file)
36
36
  elsif File.directory?(file)
37
- each_folder(subfolder + '/' + File.basename(file))
37
+ each_folder("#{subfolder}/#{File.basename(file)}")
38
38
  end
39
39
  end
40
40
  end
@@ -14,7 +14,7 @@ describe RubyRabbitmqJanus::Janus::Responses::Response, type: :responses,
14
14
  context 'when ask nice json response' do
15
15
  let(:message) { { 'data' => { 'id' => (rand * 10_000).to_i } } }
16
16
 
17
- it { expect(response.to_json).to be_kind_of(String) }
17
+ it { expect(response.to_nice_json).to be_kind_of(String) }
18
18
  end
19
19
 
20
20
  context 'when ask hash response' do
@@ -3,6 +3,7 @@
3
3
  require 'spec_helper'
4
4
 
5
5
  describe RubyRabbitmqJanus::Rabbit::Listener::From, type: :rabbit,
6
+ broken: true,
6
7
  name: :listener do
7
8
  let(:publish) do
8
9
  rabbit = RubyRabbitmqJanus::Rabbit::Connect.new.rabbit
@@ -3,6 +3,7 @@
3
3
  require 'spec_helper'
4
4
 
5
5
  describe RubyRabbitmqJanus::Rabbit::Publisher::Admin, type: :rabbit,
6
+ broken: true,
6
7
  name: :publisher_admin do
7
8
  let(:pusblish) { described_class.new }
8
9
 
@@ -2,9 +2,10 @@
2
2
 
3
3
  require 'spec_helper'
4
4
 
5
- describe RubyRabbitmqJanus::Rabbit::Publisher, type: :rabbit,
6
- name: :exclusive do
7
- let(:publish) { RubyRabbitmqJanus::Rabbit::Publisher::Exclusive.new }
5
+ describe RubyRabbitmqJanus::Rabbit::Publisher::Exclusive, type: :rabbit,
6
+ broken: true,
7
+ name: :exclusive do
8
+ let(:publish) { described_class.new }
8
9
 
9
10
  # @todo Complete Publisher exclusive test
10
11
  describe 'Exclusive' do
@@ -2,10 +2,10 @@
2
2
 
3
3
  require 'spec_helper'
4
4
 
5
- describe RubyRabbitmqJanus::Rabbit::Publisher, type: :rabbit,
6
- name: :non_exclusive do
7
- let(:publish) do
8
- end
5
+ describe RubyRabbitmqJanus::Rabbit::Publisher::NonExclusive, type: :rabbit,
6
+ broken: true,
7
+ name: :non_exclusive do
8
+ let(:publish) { described_class.new }
9
9
 
10
10
  # @todo Complete spec publisher Non Exclusive
11
11
  describe 'NonExclusive' do