ruby_rabbitmq_janus 3.0.0.pre.354 → 3.0.0.pre.384

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (76) 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/models/concerns/instances.rb +11 -6
  14. data/lib/rrj/process/concurrency.rb +15 -5
  15. data/lib/rrj/process/event.rb +7 -5
  16. data/lib/rrj/process/event_admin.rb +7 -5
  17. data/lib/rrj/process/thread_runner_concern.rb +30 -29
  18. data/lib/rrj/rabbit/base_event.rb +2 -2
  19. data/lib/rrj/rabbit/connect.rb +21 -4
  20. data/lib/rrj/rabbit/listener/base.rb +17 -1
  21. data/lib/rrj/rabbit/listener/from.rb +2 -15
  22. data/lib/rrj/rabbit/listener/from_admin.rb +2 -15
  23. data/lib/rrj/rabbit/publisher/non_exclusive.rb +3 -0
  24. data/lib/rrj/rails.rb +9 -5
  25. data/lib/rrj/rspec.rb +5 -0
  26. data/lib/rrj/task.rb +2 -0
  27. data/lib/rrj/tools/gem/config/gem.rb +1 -1
  28. data/lib/rrj/tools/gem/logger.rb +1 -2
  29. data/lib/rrj/tools/gem/requests.rb +2 -2
  30. data/spec/config/database.rb +1 -0
  31. data/spec/factories/janus_instance.rb +2 -0
  32. data/spec/ruby_rabbitmq_janus/janus/responses/errors_spec.rb +175 -0
  33. data/spec/ruby_rabbitmq_janus/janus/responses/response_spec.rb +1 -1
  34. data/spec/ruby_rabbitmq_janus/models/{janus_instance_definition_spec.rb → janus_instance_field_spec.rb} +0 -0
  35. data/spec/ruby_rabbitmq_janus/models/janus_instance_instance_spec.rb +47 -0
  36. data/spec/ruby_rabbitmq_janus/models/{janus_instance_spec.rb → janus_instance_validation_spec.rb} +10 -2
  37. data/spec/ruby_rabbitmq_janus/process/concurrencies/concurrency_spec.rb +1 -5
  38. data/spec/ruby_rabbitmq_janus/process/concurrencies/event_admin_spec.rb +3 -2
  39. data/spec/ruby_rabbitmq_janus/process/concurrencies/event_spec.rb +3 -2
  40. data/spec/ruby_rabbitmq_janus/rabbit/listener/from_spec.rb +1 -0
  41. data/spec/ruby_rabbitmq_janus/rabbit/publisher/admin_spec.rb +1 -0
  42. data/spec/ruby_rabbitmq_janus/rabbit/publisher/exclusive_spec.rb +4 -3
  43. data/spec/ruby_rabbitmq_janus/rabbit/publisher/non_exclusive_spec.rb +4 -4
  44. data/spec/ruby_rabbitmq_janus/tools/logger_spec.rb +34 -0
  45. data/spec/ruby_rabbitmq_janus/tools/replaces/admin_spec.rb +2 -2
  46. data/spec/ruby_rabbitmq_janus/tools/replaces/handle_spec.rb +1 -1
  47. data/spec/ruby_rabbitmq_janus/tools/type_spec.rb +1 -1
  48. data/spec/spec_helper.rb +27 -3
  49. data/spec/support/examples_model.rb +45 -0
  50. data/spec/support/examples_thread.rb +21 -15
  51. data/tmp/coverage/assets/0.10.2/application.css +799 -0
  52. data/tmp/coverage/assets/0.10.2/application.js +1707 -0
  53. data/tmp/coverage/assets/0.10.2/colorbox/border.png +0 -0
  54. data/tmp/coverage/assets/0.10.2/colorbox/controls.png +0 -0
  55. data/tmp/coverage/assets/0.10.2/colorbox/loading.gif +0 -0
  56. data/tmp/coverage/assets/0.10.2/colorbox/loading_background.png +0 -0
  57. data/tmp/coverage/assets/0.10.2/favicon_green.png +0 -0
  58. data/tmp/coverage/assets/0.10.2/favicon_red.png +0 -0
  59. data/tmp/coverage/assets/0.10.2/favicon_yellow.png +0 -0
  60. data/tmp/coverage/assets/0.10.2/loading.gif +0 -0
  61. data/tmp/coverage/assets/0.10.2/magnify.png +0 -0
  62. data/tmp/coverage/assets/0.10.2/smoothness/images/ui-bg_flat_0_aaaaaa_40x100.png +0 -0
  63. data/tmp/coverage/assets/0.10.2/smoothness/images/ui-bg_flat_75_ffffff_40x100.png +0 -0
  64. data/tmp/coverage/assets/0.10.2/smoothness/images/ui-bg_glass_55_fbf9ee_1x400.png +0 -0
  65. data/tmp/coverage/assets/0.10.2/smoothness/images/ui-bg_glass_65_ffffff_1x400.png +0 -0
  66. data/tmp/coverage/assets/0.10.2/smoothness/images/ui-bg_glass_75_dadada_1x400.png +0 -0
  67. data/tmp/coverage/assets/0.10.2/smoothness/images/ui-bg_glass_75_e6e6e6_1x400.png +0 -0
  68. data/tmp/coverage/assets/0.10.2/smoothness/images/ui-bg_glass_95_fef1ec_1x400.png +0 -0
  69. data/tmp/coverage/assets/0.10.2/smoothness/images/ui-bg_highlight-soft_75_cccccc_1x100.png +0 -0
  70. data/tmp/coverage/assets/0.10.2/smoothness/images/ui-icons_222222_256x240.png +0 -0
  71. data/tmp/coverage/assets/0.10.2/smoothness/images/ui-icons_2e83ff_256x240.png +0 -0
  72. data/tmp/coverage/assets/0.10.2/smoothness/images/ui-icons_454545_256x240.png +0 -0
  73. data/tmp/coverage/assets/0.10.2/smoothness/images/ui-icons_888888_256x240.png +0 -0
  74. data/tmp/coverage/assets/0.10.2/smoothness/images/ui-icons_cd0a0a_256x240.png +0 -0
  75. data/tmp/coverage/index.html +21339 -0
  76. metadata +73 -10
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c734f054b82c7313cc2f700856897005589fc8cd85083b21562ee2574ad038eb
4
- data.tar.gz: 617e6caa75c5cad2280d07c6056161a25ed549d825fb9524ae6cc3c098132085
3
+ metadata.gz: e3f09817fed0214a2ce8a776ea6cb6c7c3ea893c24f56af5c2cec9855883d5f5
4
+ data.tar.gz: 108b9f75fbb86c4698ada11ff575568e5e80d7ee42c46a05da9713b375414868
5
5
  SHA512:
6
- metadata.gz: 9ec5a373c987a2bf9c18d2ea1b1478a6a4814967af89d73cdc7a04cd0cd79922d8f9e7ad6d5d4da555e64f1f23c13598da1ba403d7f84741da424154e92ff22a
7
- data.tar.gz: 74ab344770f32f388f0fcb009dd90e82388b74b1dd8732903ef6c658a0b714b084f7595bee353419510ef08f65f2fc41499e09a2a12c1ef6f050802bf2d28918
6
+ metadata.gz: fbfce5a5a397afbfcb3e25a4f435f7149382584146099ab6f0e8eb73e4f64095e38401a74b38c581765e3c6592f5b7807f88007bdd2b91ca172e7241528b0fea
7
+ data.tar.gz: 32d45c9f76089d812d71ca10b2c085f160cabe3f85ffbe54d56075cc9db81eaaf83a111d05c8536d3d63cc40084fffc5bb52241ab853b4988a9636eb6d042a9d
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
@@ -12,32 +12,37 @@ module RubyRabbitmqJanus
12
12
  module ClassMethods
13
13
  # Disable an instance
14
14
  def disable(session_id)
15
- JanusInstance.find_by(session: session_id).set(enable: false)
15
+ find_by_session(session_id).set(enable: false)
16
+ end
17
+
18
+ # Enable an instance
19
+ def enable(session_id)
20
+ find_by_session(session_id).set(enable: true)
16
21
  end
17
22
 
18
23
  # Clean all instance disabled
19
24
  def destroys
20
- JanusInstance.where(enable: false).delete_all
25
+ where(enable: false).delete_all
21
26
  end
22
27
 
23
28
  # Search a record by instance number
24
29
  def find_by_instance(instance_search)
25
- JanusInstance.find_by(instance: instance_search)
30
+ find_by(instance: instance_search)
26
31
  end
27
32
 
28
33
  # Search a record by session number
29
34
  def find_by_session(session_search)
30
- JanusInstance.find_by(session: session_search)
35
+ find_by(session_id: session_search)
31
36
  end
32
37
 
33
38
  # Get all instance active
34
39
  def enabled
35
- JanusInstance.where(enable: true)
40
+ where(enable: true)
36
41
  end
37
42
 
38
43
  # Get all instance not active
39
44
  def disabled
40
- JanusInstance.where(enable: false)
45
+ where(enable: false)
41
46
  end
42
47
  end
43
48
  end
@@ -27,19 +27,29 @@ module RubyRabbitmqJanus
27
27
  def initialize_thread
28
28
  @rabbit.transaction_long { transaction_running }
29
29
  rescue Interrupt
30
- ::Log.warn \
31
- "Close a connection with RabbitMQ instance for #{self.class.name}"
32
- @rabbit.close
30
+ ::Log.warn "This process has been interupted #{class_name}"
31
+ close
32
+ else
33
+ 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
42
+ end
43
+
44
+ def close
45
+ ::Log.warn \
46
+ "Close a connection with RabbitMQ instance for #{class_name}"
47
+ @rabbit.close
37
48
  end
38
49
  end
39
50
  end
40
51
  end
41
52
  end
42
53
 
43
- require 'rrj/process/thread_runner_concern'
44
54
  require 'rrj/process/event'
45
55
  require 'rrj/process/event_admin'
@@ -1,5 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require 'rrj/process/thread_runner_concern'
4
+
3
5
  module RubyRabbitmqJanus
4
6
  module Process
5
7
  module Concurrencies
@@ -16,17 +18,17 @@ module RubyRabbitmqJanus
16
18
 
17
19
  private
18
20
 
19
- def raise_nil_block
20
- raise RubyRabbitmqJanus::Errors::Process::Event::Run
21
- end
22
-
23
21
  def name_publisher
24
- :publish
22
+ :pub_classic
25
23
  end
26
24
 
27
25
  def publisher
28
26
  Rabbit::Listener::From.new(rabbit)
29
27
  end
28
+
29
+ def raise_nil_block
30
+ raise RubyRabbitmqJanus::Errors::Process::Event::Run
31
+ end
30
32
  end
31
33
  end
32
34
  end
@@ -1,5 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require 'rrj/process/thread_runner_concern'
4
+
3
5
  module RubyRabbitmqJanus
4
6
  module Process
5
7
  module Concurrencies
@@ -16,17 +18,17 @@ module RubyRabbitmqJanus
16
18
 
17
19
  private
18
20
 
19
- def raise_nil_block
20
- raise RubyRabbitmqJanus::Errors::Process::EventAdmin::Run
21
- end
22
-
23
21
  def name_publisher
24
- :publish_adm
22
+ :pub_admin
25
23
  end
26
24
 
27
25
  def publisher
28
26
  Rabbit::Listener::FromAdmin.new(rabbit)
29
27
  end
28
+
29
+ def raise_nil_block
30
+ raise RubyRabbitmqJanus::Errors::Process::EventAdmin::Run
31
+ end
30
32
  end
31
33
  end
32
34
  end
@@ -13,41 +13,42 @@ module RubyRabbitmqJanus
13
13
  module ThreadRunnerConcern
14
14
  extend ActiveSupport::Concern
15
15
 
16
- # Initialize an process (event/event_admin) and configure
17
- # the life cycle to thread.
18
- def initialize
19
- super
20
- @thread = Thread.new { initialize_thread }
21
- @thread.abort_on_exception = true
22
- end
16
+ included do
17
+ # Initialize an process (event/event_admin) and configure
18
+ # the life cycle to thread.
19
+ def initialize
20
+ super
21
+ @thread = Thread.new { initialize_thread }
22
+ end
23
23
 
24
- # Create a thread for execute a block code in a thread.
25
- # This code is outside to `RRJ` gem so is very important
26
- # to be sure this code execution is not fail.
27
- #
28
- # @param [Proc] block Block code for execute action when queue
29
- # standard 'from-janus' receive a message.This block is sending to
30
- # publisher created for this thread.
31
- #
32
- # @return [Thread] It's a thread who listen queue and execute action
33
- def run(&block)
34
- raise_nil_block unless block_given?
24
+ # Create a thread for execute a block code in a thread.
25
+ # This code is outside to `RRJ` gem so is very important
26
+ # to be sure this code execution is not fail.
27
+ #
28
+ # @param [Proc] block Block code for execute action when queue
29
+ # standard 'from-janus' receive a message.This block is sending to
30
+ # publisher created for this thread.
31
+ #
32
+ # @return [Thread] It's a thread who listen queue and execute action
33
+ def run(&block)
34
+ raise_nil_block unless block
35
35
 
36
- @thread.join
37
- Thread.new do
38
- loop do
39
- @thread.thread_variable_get(name_publisher).listen_events(&block)
40
- rescue => exception
41
- ::Log.warn 'An exception to was encountered in the thread !'
42
- ::Log.warn exception
36
+ @thread.join
37
+ Thread.new do
38
+ loop do
39
+ @thread.thread_variable_get(name_publisher)
40
+ .listen_events(&block)
41
+ rescue => exception
42
+ ::Log.warn exception
43
+ end
43
44
  end
44
45
  end
45
- end
46
46
 
47
- private
47
+ private
48
48
 
49
- def transaction_running
50
- @thread.thread_variable_set(name_publisher, publisher)
49
+ def transaction_running
50
+ @thread.thread_variable_set(name_publisher, publisher)
51
+ end
51
52
  end
52
53
  end
53
54
  end
@@ -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