ruby_rabbitmq_janus 3.0.0.pre.358 → 3.0.0.pre.385

Sign up to get free protection for your applications and to get access to all the features.
Files changed (37) 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/listener/base.rb +17 -1
  18. data/lib/rrj/rabbit/listener/from.rb +2 -15
  19. data/lib/rrj/rabbit/listener/from_admin.rb +2 -15
  20. data/lib/rrj/rabbit/publisher/non_exclusive.rb +3 -0
  21. data/lib/rrj/rspec.rb +5 -0
  22. data/lib/rrj/task.rb +2 -0
  23. data/lib/rrj/tools/gem/config/gem.rb +1 -1
  24. data/lib/rrj/tools/gem/logger.rb +1 -2
  25. data/lib/rrj/tools/gem/requests.rb +2 -2
  26. data/spec/ruby_rabbitmq_janus/janus/responses/response_spec.rb +1 -1
  27. data/spec/ruby_rabbitmq_janus/rabbit/listener/from_spec.rb +1 -0
  28. data/spec/ruby_rabbitmq_janus/rabbit/publisher/admin_spec.rb +1 -0
  29. data/spec/ruby_rabbitmq_janus/rabbit/publisher/exclusive_spec.rb +4 -3
  30. data/spec/ruby_rabbitmq_janus/rabbit/publisher/non_exclusive_spec.rb +4 -4
  31. data/spec/ruby_rabbitmq_janus/tools/replaces/admin_spec.rb +2 -2
  32. data/spec/ruby_rabbitmq_janus/tools/replaces/handle_spec.rb +1 -1
  33. data/spec/ruby_rabbitmq_janus/tools/type_spec.rb +1 -1
  34. data/spec/spec_helper.rb +4 -2
  35. data/spec/support/examples_thread.rb +3 -3
  36. data/tmp/coverage/index.html +2180 -1994
  37. metadata +28 -8
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d71f0e648c88b66a515f531f9363854ac8bfe3219412ab6c25dbbad0e35c49ae
4
- data.tar.gz: f6188b1fff85bd230cc0d44356c879388eb32d809e70a26248c00261e5ff23de
3
+ metadata.gz: 4f2ca0d58fac3e63edecd2943918395a4fe895899fe50ebbe98404fab974f8a2
4
+ data.tar.gz: 18f8ef959a17619e9b2dedd2ca65f6ad407312230128ff5b7444d992ce78e381
5
5
  SHA512:
6
- metadata.gz: ea2469541044db09a0b6fdfb34371f81cd441b7e2a8e566876628a88a2742b8be18e5af996eef47df3adf9d2a8076a5c562a0e4116a3b0a9bae2dc5b185133b7
7
- data.tar.gz: b611d921872a181c05d4da95f7dddc75f032842fa48ba3435bba379465267b8e3674b99d84149e577d9252665156115bf9f0ba6894e0c091920542248aef4279
6
+ metadata.gz: 80b1d227f402bcb6df27f30e6e6ccf5f87e5dfc614dade152986f8ab5c146450cb4a7876eee551ebbce28dc9bcdd771e6746936a9f3dd4e4f76a30966106b313
7
+ data.tar.gz: fb2d220836e330d50c26b89fdfcb7cb393e10fd7d2e9c5cd8c54e0b3d79c1b95fce1da43a70db7e9ffeaea14b47a97201fe2128c8b6cfdd636ea145d6c25bd68
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
@@ -36,7 +36,7 @@ module RubyRabbitmqJanus
36
36
  end
37
37
 
38
38
  def opts_subs
39
- { block: false, manual_ack: true, arguments: { 'x-priority': 2 } }
39
+ { block: false, manual_ack: false, arguments: { 'x-priority': 2 } }
40
40
  end
41
41
 
42
42
  def info_subscribe(info, _prop, payload)
@@ -51,6 +51,22 @@ module RubyRabbitmqJanus
51
51
  raise Errors::Rabbit::Listener::ResponseEmpty, response \
52
52
  if response.to_hash.size.zero?
53
53
  end
54
+
55
+ def subscribe_queue
56
+ rabbit.prefetch(1)
57
+ reply.bind(binding).subscribe(opts_subs) do |info, prop, payload|
58
+ info_subscribe(info, prop, payload)
59
+ synchronize_response(payload)
60
+ end
61
+ end
62
+
63
+ def synchronize_response(payload)
64
+ lock.synchronize do
65
+ response = response_class(payload)
66
+ responses.push(response)
67
+ end
68
+ semaphore.signal
69
+ end
54
70
  end
55
71
  end
56
72
  end
@@ -15,21 +15,8 @@ module RubyRabbitmqJanus
15
15
  rabbit.queue(Tools::Config.instance.queue_from)
16
16
  end
17
17
 
18
- def subscribe_queue
19
- rabbit.prefetch(1)
20
- reply.bind(binding).subscribe(opts_subs) do |info, prop, payload|
21
- info_subscribe(info, prop, payload)
22
- synchronize_response(info, payload)
23
- end
24
- end
25
-
26
- def synchronize_response(info, payload)
27
- lock.synchronize do
28
- response = Janus::Responses::Event.new(JSON.parse(payload))
29
- responses.push(response)
30
- end
31
- rabbit.acknowledge(info.delivery_tag, false)
32
- semaphore.signal
18
+ def response_class(payload)
19
+ Janus::Responses::Event.new(JSON.parse(payload))
33
20
  end
34
21
  end
35
22
  end
@@ -15,21 +15,8 @@ module RubyRabbitmqJanus
15
15
  rabbit.queue(Tools::Config.instance.queue_admin_from)
16
16
  end
17
17
 
18
- def subscribe_queue
19
- rabbit.prefetch(1)
20
- reply.bind(binding).subscribe(opts_subs) do |info, prop, payload|
21
- info_subscribe(info, prop, payload)
22
- synchronize_response(info, payload)
23
- end
24
- end
25
-
26
- def synchronize_response(info, payload)
27
- lock.synchronize do
28
- response = Janus::Responses::Admin.new(JSON.parse(payload))
29
- responses.push(response)
30
- end
31
- rabbit.acknowledge(info.delivery_tag, false)
32
- semaphore.signal
18
+ def response_class(payload)
19
+ Janus::Responses::Admin.new(JSON.parse(payload))
33
20
  end
34
21
  end
35
22
  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