ruby_rabbitmq_janus 3.0.0.pre.352 → 3.0.0.pre.382

Sign up to get free protection for your applications and to get access to all the features.
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 +9 -3
  15. data/lib/rrj/process/event.rb +8 -26
  16. data/lib/rrj/process/event_admin.rb +8 -26
  17. data/lib/rrj/process/thread_runner_concern.rb +56 -0
  18. data/lib/rrj/rabbit/base_event.rb +2 -2
  19. data/lib/rrj/rabbit/connect.rb +12 -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 +18 -12
  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 +21249 -0
  76. metadata +74 -10
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 9410fdf3db086fdaf0c7abd7c822612977718f0d2059869ec0bfd5522e30dacf
4
- data.tar.gz: dfe4addba32bc68b336cb4db8177a791589cde45ed73d78799fc7d298ef129a0
3
+ metadata.gz: 5e2788aaa9bf06b85b431dfa06ac04bb1315bbf2a0eebdd73b91367e535b4cea
4
+ data.tar.gz: deccabc4e76a96d6db5335625cef5086c7aabcad8930590cff866d6c7abbf9e7
5
5
  SHA512:
6
- metadata.gz: 99ea49a811322ecc33e84b2f7fc03bc181b9b515520debbceaf922b59fc0007073ae571f4fb1e9004052c04596606efabacbfdda8a7157bbf411d8ca8f1b7900
7
- data.tar.gz: 2ca3d7bc242cb865bc397f21d43be8504af0b2e40cb9c77907f4120867a2b10adc8fa9ada6d3b5714b9f4c33d41d871d1bc12cb9a92010731a9dbd47909b0c2b
6
+ metadata.gz: cab7ca08efd87ef15d24c71612d96d6b8deb460619af6ea79ff6f09cc025dbf1c2683cdd145bcfba781df2202b94ff9a3a4a7fcd99e9247016a2790dc313ba9a
7
+ data.tar.gz: 32c1868c00b6c01a7f76b870ecc4f064c2c959f32bf54025fd94fca8cf93dc61cdf87847a1a978d2cf15b6470a2a27d58bb324014cdd6181cf3f84df3dfcfd19
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
@@ -22,18 +22,24 @@ module RubyRabbitmqJanus
22
22
 
23
23
  private
24
24
 
25
+ attr_reader :lock, :condition, :rabbit
26
+
25
27
  def initialize_thread
26
28
  @rabbit.transaction_long { transaction_running }
27
29
  rescue Interrupt
28
- ::Log.info "Stop transaction #{self.class.name}"
30
+ ::Log.warn "This process has been interupted #{class_name}"
31
+ ::Log.warn \
32
+ "Close a connection with RabbitMQ instance for #{class_name}"
29
33
  @rabbit.close
30
34
  end
31
35
 
32
36
  def info_thread
33
- "Create an thread -- #{self.class.name}"
37
+ "Create an thread -- #{class_name}"
34
38
  end
35
39
 
36
- attr_reader :lock, :condition, :rabbit
40
+ def class_name
41
+ self.class.name
42
+ end
37
43
  end
38
44
  end
39
45
  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
@@ -12,40 +14,20 @@ module RubyRabbitmqJanus
12
14
  #
13
15
  # @see file:/config/default.md For more information to config file used.
14
16
  class Event < Concurrency
15
- NAME_VAR = :publish
16
-
17
- def initialize
18
- super
19
- @thread = Thread.new { initialize_thread }
20
- end
17
+ include RubyRabbitmqJanus::Process::Concurrencies::ThreadRunnerConcern
21
18
 
22
- # Create a thread for execute a block code in a thread
23
- #
24
- # @param [Proc] block Block code for execute action when queue
25
- # standard 'from-janus' receive a message.This block is sending to
26
- # publisher created for this thread.
27
- #
28
- # @return [Thread] It's a thread who listen queue and execute action
29
- def run(&block)
30
- raise RubyRabbitmqJanus::Errors::Process::Event::Run \
31
- unless block_given?
19
+ private
32
20
 
33
- @thread.join
34
- Thread.new do
35
- loop do
36
- @thread.thread_variable_get(NAME_VAR).listen_events(&block)
37
- end
38
- end
21
+ def name_publisher
22
+ :pub_classic
39
23
  end
40
24
 
41
- private
42
-
43
25
  def publisher
44
26
  Rabbit::Listener::From.new(rabbit)
45
27
  end
46
28
 
47
- def transaction_running
48
- @thread.thread_variable_set(NAME_VAR, publisher)
29
+ def raise_nil_block
30
+ raise RubyRabbitmqJanus::Errors::Process::Event::Run
49
31
  end
50
32
  end
51
33
  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
@@ -12,40 +14,20 @@ module RubyRabbitmqJanus
12
14
  #
13
15
  # @see file:/config/default.md For more information to config file used.
14
16
  class EventAdmin < Concurrency
15
- NAME_VAR = :publish_adm
16
-
17
- def initialize
18
- super
19
- @thread = Thread.new { initialize_thread }
20
- end
17
+ include RubyRabbitmqJanus::Process::Concurrencies::ThreadRunnerConcern
21
18
 
22
- # Create a thread for execute a block code in a thread
23
- #
24
- # @param [Proc] block Block code for execute action when queue
25
- # standard 'from-janus' receive a message.This block is sending to
26
- # publisher created for this thread.
27
- #
28
- # @return [Thread] It's a thread who listen queue and execute action
29
- def run(&block)
30
- raise RubyRabbitmqJanus::Errors::Process::EventAdmin::Run \
31
- unless block_given?
19
+ private
32
20
 
33
- @thread.join
34
- Thread.new do
35
- loop do
36
- @thread.thread_variable_get(NAME_VAR).listen_events(&block)
37
- end
38
- end
21
+ def name_publisher
22
+ :pub_admin
39
23
  end
40
24
 
41
- private
42
-
43
25
  def publisher
44
26
  Rabbit::Listener::FromAdmin.new(rabbit)
45
27
  end
46
28
 
47
- def transaction_running
48
- @thread.thread_variable_set(NAME_VAR, publisher)
29
+ def raise_nil_block
30
+ raise RubyRabbitmqJanus::Errors::Process::EventAdmin::Run
49
31
  end
50
32
  end
51
33
  end
@@ -0,0 +1,56 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'active_support/concern'
4
+
5
+ module RubyRabbitmqJanus
6
+ module Process
7
+ module Concurrencies
8
+ # Module injected in Concurrencies classes.
9
+ #
10
+ # Manage threads for public/admin queue to rabbitmq.
11
+ #
12
+ # :reek:ModuleInitialize
13
+ module ThreadRunnerConcern
14
+ extend ActiveSupport::Concern
15
+
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
+
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
+
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
44
+ end
45
+ end
46
+
47
+ private
48
+
49
+ def transaction_running
50
+ @thread.thread_variable_set(name_publisher, publisher)
51
+ end
52
+ end
53
+ end
54
+ end
55
+ end
56
+ 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