ruby_rabbitmq_janus 2.1.1 → 2.2.0.pre.42

Sign up to get free protection for your applications and to get access to all the features.
Files changed (40) hide show
  1. checksums.yaml +4 -4
  2. data/config/default.md +3 -4
  3. data/config/default.yml +7 -6
  4. data/lib/generators/ruby_rabbitmq_janus/templates/migration.rb +1 -0
  5. data/lib/rrj/errors/error.rb +16 -4
  6. data/lib/rrj/errors/janus/janus.rb +0 -1
  7. data/lib/rrj/errors/janus/processus/keepalive.rb +5 -17
  8. data/lib/rrj/errors/janus/processus/keepalive/initializer.rb +61 -0
  9. data/lib/rrj/errors/janus/processus/keepalive/thread.rb +16 -0
  10. data/lib/rrj/errors/janus/processus/keepalive/timer.rb +16 -0
  11. data/lib/rrj/errors/rabbit/connect.rb +12 -12
  12. data/lib/rrj/errors/tools/gem/cluster.rb +7 -7
  13. data/lib/rrj/errors/tools/gem/config.rb +0 -14
  14. data/lib/rrj/errors/tools/gem/option.rb +7 -0
  15. data/lib/rrj/info.rb +1 -1
  16. data/lib/rrj/init.rb +0 -11
  17. data/lib/rrj/janus/processus/concurrency.rb +8 -5
  18. data/lib/rrj/janus/processus/event.rb +8 -5
  19. data/lib/rrj/janus/processus/keepalive/keepalive_initializer.rb +74 -0
  20. data/lib/rrj/janus/processus/keepalive/keepalive_message.rb +52 -0
  21. data/lib/rrj/janus/processus/keepalive/keepalive_thread.rb +71 -0
  22. data/lib/rrj/janus/processus/keepalive/keepalive_timer.rb +64 -0
  23. data/lib/rrj/janus/responses/response.rb +8 -1
  24. data/lib/rrj/janus/transactions/transaction.rb +1 -1
  25. data/lib/rrj/models/active_record.rb +6 -2
  26. data/lib/rrj/models/concerns/janus_instance_callbacks.rb +69 -0
  27. data/lib/rrj/models/concerns/{janus_instance_concern.rb → janus_instance_methods.rb} +7 -10
  28. data/lib/rrj/models/concerns/janus_instance_validations.rb +20 -0
  29. data/lib/rrj/models/mongoid.rb +7 -2
  30. data/lib/rrj/rabbit/connect.rb +14 -12
  31. data/lib/rrj/rabbit/publish/keepalive.rb +33 -0
  32. data/lib/rrj/rabbit/publish/publisher.rb +1 -0
  33. data/lib/rrj/tools/gem/cluster.rb +15 -25
  34. data/lib/rrj/tools/gem/config.rb +1 -8
  35. data/lib/rrj/tools/gem/option.rb +16 -9
  36. data/spec/rrj/tools/gem/rrj_cluster_spec.rb +2 -6
  37. data/spec/rrj/tools/gem/rrj_config_spec.rb +1 -6
  38. data/spec/support/schemas/config/config.json +13 -5
  39. metadata +30 -7
  40. data/lib/rrj/janus/processus/keepalive.rb +0 -79
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 16df5ab4b2d2425a330c7aa2a5d6a53504bfe9a7
4
- data.tar.gz: ecaae36f0768b95b8a39d6607b89dff66ff245d2
3
+ metadata.gz: d5f7f8a44b723ed992abbde848a25695bc35df85
4
+ data.tar.gz: 1c4069bc56dd828876f35e3ed9041f78ee1addfd
5
5
  SHA512:
6
- metadata.gz: 1842090e0975c39a141d3b3a3567afd9c027e1035e4ef643fb9ab59cf0af1fd487d1629d4fd4c1c82f1113ef4c94f3391f97a13bbdf3354dd066fddb581f5f15
7
- data.tar.gz: 62986f78ce51decd7dbb254e38898571da47569b7aeb45ad0e4faa51d63f288c2e63db53a8c111c5a5a2e836a5871258deb92b5f709ceb8ca97642a4277f5827
6
+ metadata.gz: 47cb62ccb6c9ae3c8fda9c57aa30e9aded8a2c75c28521b39338e5cbd68261975cb46cde52604f669484a6679c128ca93b48ea867472e998a7ea86b7b2d75d67
7
+ data.tar.gz: 882fae4ab47b161503ed0ea8c7b7feb84bcd58bf02e020d71551f8b487278e245ef07c51a7cc4823ec417092fd171b12a8ff352579706dfb0fb7ca6118d8fa02
data/config/default.md CHANGED
@@ -23,15 +23,14 @@ queues:
23
23
  to: to-janus-admin
24
24
 
25
25
  janus:
26
- cluster:
27
- enabled: false
28
- count: 0
29
26
  session:
30
27
  keepalive: 45
31
28
  plugins:
32
29
  - janus.plugin.echotest
33
30
 
34
31
  gem:
32
+ cluster:
33
+ enabled: true
35
34
  log:
36
35
  level: info
37
36
  ```
@@ -42,7 +41,7 @@ For customizing a configuration add a yml file in your rails project in
42
41
  `config/ruby-rabbitmq-janus.yml`, or use rails generator with command `rails generate
43
42
  ruby_rabbitmq_janus:configuration`.
44
43
 
45
- ## Ressources
44
+ ## Resources
46
45
 
47
46
  * [Configuration of RabbitMQ](https://www.rabbitmq.com/configure.html#config-items)
48
47
  * [Configuration of Janus queue](https://janus.conf.meetecho.com/docs/rest.html#rabbit)
data/config/default.yml CHANGED
@@ -30,12 +30,6 @@ queues:
30
30
 
31
31
  # Janus plugin used
32
32
  janus:
33
- # Options for clusturing Janus Instance
34
- cluster:
35
- # Enable/Disable cluster mode
36
- enabled: false
37
- # Number to cluster
38
- count: 1
39
33
  # Option for sessions
40
34
  session:
41
35
  # Define time to send a keepalive message in seconds
@@ -48,6 +42,13 @@ janus:
48
42
 
49
43
  # Options gem
50
44
  gem:
45
+ # Options for clusturing Janus Instance
46
+ cluster:
47
+ # Enable/Disable cluster mode
48
+ # if you disable cluster mode, the initializer to this gem start a session
49
+ # automatically with Janus, but if you enable think to start a session for
50
+ # each instance
51
+ enabled: true
51
52
  # Option for logs
52
53
  log:
53
54
  # Define level to log
@@ -9,6 +9,7 @@ class CreateRubyRabbitmqJanusTables < ActiveRecord::Migration[5.0]
9
9
  table.integer :instance
10
10
  table.integer :session, limit: 8
11
11
  table.boolean :enable
12
+ table.boolean :thread
12
13
  end
13
14
  end
14
15
  end
@@ -7,15 +7,27 @@ module RubyRabbitmqJanus
7
7
  #
8
8
  # Define errors to gems
9
9
  class RRJError < StandardError
10
- # Initialize a error standard in this gem
10
+ # Initialize a error standard in this gem and writing in log file
11
11
  #
12
12
  # @param [String] message Text returning in raise
13
13
  # @param [Symbol] level Important to error
14
14
  def initialize(message, level)
15
15
  super(message)
16
- log = RubyRabbitmqJanus::Tools::Log.instance
17
- RubyRabbitmqJanus::Tools::Log.instance_method(level)\
18
- .bind(log).call(message)
16
+ write_error(message, level)
17
+ end
18
+
19
+ private
20
+
21
+ def log
22
+ RubyRabbitmqJanus::Tools::Log
23
+ end
24
+
25
+ def logger
26
+ log.instance
27
+ end
28
+
29
+ def write_error(message, level)
30
+ log.instance_method(level).bind(logger).call(message)
19
31
  end
20
32
  end
21
33
  end
@@ -17,7 +17,6 @@ module RubyRabbitmqJanus
17
17
  end
18
18
 
19
19
  require 'rrj/errors/janus/processus/concurency'
20
- require 'rrj/errors/janus/processus/keepalive'
21
20
  require 'rrj/errors/janus/processus/event'
22
21
 
23
22
  require 'rrj/errors/janus/messages/message'
@@ -9,25 +9,13 @@ module RubyRabbitmqJanus
9
9
  # Define a super class for all error in Janus::Concurency::Keepalive
10
10
  class BaseKeepalive < RubyRabbitmqJanus::Errors::Janus::BaseConcurency
11
11
  def initialize(message)
12
- super "[Keepalive] #{message}"
13
- end
14
- end
15
-
16
- module Keepalive
17
- # Error for Janus::Concurency::Keepalive#initialize
18
- class Initializer < RubyRabbitmqJanus::Errors::Janus::BaseKeepalive
19
- def initializer
20
- super 'Error keepalive initializer'
21
- end
22
- end
23
-
24
- # Error for Janus::Concurency::Keepalive#session
25
- class Session < RubyRabbitmqJanus::Errors::Janus::BaseKeepalive
26
- def initializer
27
- super 'Error return session number'
28
- end
12
+ super "[Keepalive]#{message}"
29
13
  end
30
14
  end
31
15
  end
32
16
  end
33
17
  end
18
+
19
+ require 'rrj/errors/janus/processus/keepalive/initializer'
20
+ require 'rrj/errors/janus/processus/keepalive/thread'
21
+ require 'rrj/errors/janus/processus/keepalive/timer'
@@ -0,0 +1,61 @@
1
+ # frozen_string_literal: true
2
+
3
+ # :reek:IrresponsibleModule
4
+ #
5
+ # rubocop:disable Metrics/LineLength
6
+ # rubocop:disable Style/Documentation
7
+
8
+ module RubyRabbitmqJanus
9
+ module Errors
10
+ module Janus
11
+ # Define a super class for all error in Janus::Concurency::Keepalive
12
+ class BaseKeepaliveInitializer < BaseKeepalive
13
+ def initialize(message)
14
+ super "[Initializer] #{message}"
15
+ end
16
+ end
17
+
18
+ module KeepaliveInitializer
19
+ # Error for Janus::Concurency::Keepalive#initialize
20
+ class Initializer < RubyRabbitmqJanus::Errors::Janus::BaseKeepaliveInitializer
21
+ def initializer
22
+ super 'Error keepalive initializer'
23
+ end
24
+ end
25
+
26
+ # Error for Janus::Concurency::Keepalive#session
27
+ class Session < RubyRabbitmqJanus::Errors::Janus::BaseKeepaliveInitializer
28
+ def initializer
29
+ super 'Error return session number'
30
+ end
31
+ end
32
+
33
+ class Thread < RubyRabbitmqJanus::Errors::Janus::BaseKeepaliveInitializer
34
+ def initializer
35
+ super 'Error for get Object Thread ID'
36
+ end
37
+ end
38
+
39
+ class ThreadStart < RubyRabbitmqJanus::Errors::Janus::BaseKeepaliveInitializer
40
+ def initializer
41
+ super 'Error for starting timer in thread'
42
+ end
43
+ end
44
+
45
+ class ThreadStop < RubyRabbitmqJanus::Errors::Janus::BaseKeepaliveInitializer
46
+ def initializer
47
+ super 'Error for stoping timer in thread'
48
+ end
49
+ end
50
+
51
+ class ThreadDelete < RubyRabbitmqJanus::Errors::Janus::BaseKeepaliveInitializer
52
+ def initializer
53
+ super 'Error for destroy thread'
54
+ end
55
+ end
56
+ end
57
+ end
58
+ end
59
+ end
60
+ # rubocop:enable Style/Documentation
61
+ # rubocop:enable Metrics/LineLength
@@ -0,0 +1,16 @@
1
+ # frozen_string_literal: true
2
+
3
+ # :reek:IrresponsibleModule
4
+
5
+ module RubyRabbitmqJanus
6
+ module Errors
7
+ module Janus
8
+ # Define a super class for all error in Janus::Concurency::Keepalive
9
+ class BaseKeepaliveThread < BaseKeepalive
10
+ def initialize(message)
11
+ super "[Thread] #{message}"
12
+ end
13
+ end
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,16 @@
1
+ # frozen_string_literal: true
2
+
3
+ # :reek:IrresponsibleModule
4
+
5
+ module RubyRabbitmqJanus
6
+ module Errors
7
+ module Janus
8
+ # Define a super class for all error in Janus::Concurency::Keepalive
9
+ class BaseKeepaliveTimer < BaseKeepalive
10
+ def initialize(message)
11
+ super "[Timer] #{message}"
12
+ end
13
+ end
14
+ end
15
+ end
16
+ end
@@ -13,43 +13,43 @@ module RubyRabbitmqJanus
13
13
  module Connect
14
14
  # Error for Rabbit::Connect#initialize
15
15
  class Initialize < RubyRabbitmqJanus::Errors::Rabbit::BaseConnect
16
- def initialize
17
- super 'Error in initializer'
16
+ def initialize(error)
17
+ super "Error in initializer #{error}"
18
18
  end
19
19
  end
20
20
 
21
21
  # Error for Rabbit::Connect#transaction_short
22
22
  class TransactionShort < RubyRabbitmqJanus::Errors::Rabbit::BaseConnect
23
- def initialize
24
- super 'Error during transaction with RabbitMQ'
23
+ def initialize(error)
24
+ super "Error during transaction with RabbitMQ #{error}"
25
25
  end
26
26
  end
27
27
 
28
28
  # Error for Rabbit::Connect#transaction_long
29
29
  class TransactionLong < RubyRabbitmqJanus::Errors::Rabbit::BaseConnect
30
- def initialize
31
- super 'Error during transaction with RabbitMQ'
30
+ def initialize(error)
31
+ super "Error during transaction with RabbitMQ #{error}"
32
32
  end
33
33
  end
34
34
 
35
35
  # Error for Rabbit::Connect#start
36
36
  class Start < RubyRabbitmqJanus::Errors::Rabbit::BaseConnect
37
- def initialize
38
- super 'Error for starting connection with RabbitMQ'
37
+ def initialize(error)
38
+ super "Error for starting connection with RabbitMQ #{error}"
39
39
  end
40
40
  end
41
41
 
42
42
  # Error for Rabbit::Connect#close
43
43
  class Close < RubyRabbitmqJanus::Errors::Rabbit::BaseConnect
44
- def initialize
45
- super 'Error for closing connection with RabbitMQ'
44
+ def initialize(error)
45
+ super "Error for closing connection with RabbitMQ #{error}"
46
46
  end
47
47
  end
48
48
 
49
49
  # Error for Rabbit::Connect#channel
50
50
  class Channel < RubyRabbitmqJanus::Errors::Rabbit::BaseConnect
51
- def initialize
52
- super 'Error for create channel in RabbitMQ instance'
51
+ def initialize(error)
52
+ super "Error for create channel in RabbitMQ instance #{error}"
53
53
  end
54
54
  end
55
55
  end
@@ -18,13 +18,6 @@ module RubyRabbitmqJanus
18
18
  end
19
19
  end
20
20
 
21
- # Error for Tools::Option#create_sessions
22
- class CreateSessions < RubyRabbitmqJanus::Errors::Tools::BaseCluster
23
- def initalize
24
- super 'Error for creating sessions'
25
- end
26
- end
27
-
28
21
  # Error for Tools::Option#queue_to
29
22
  class QueueTo < RubyRabbitmqJanus::Errors::Tools::BaseCluster
30
23
  def initalize
@@ -38,6 +31,13 @@ module RubyRabbitmqJanus
38
31
  super 'Error for create string queue_admin_to'
39
32
  end
40
33
  end
34
+
35
+ # Error if restart thread to instance failed
36
+ class RestartInstance < RubyRabbitmqJanus::Errors::Tools::BaseCluster
37
+ def initialize(option)
38
+ super "Error for restart thread to instance #{option}"
39
+ end
40
+ end
41
41
  end
42
42
  end
43
43
  end
@@ -76,20 +76,6 @@ module RubyRabbitmqJanus
76
76
  "with parameter #{parameter}", :warn
77
77
  end
78
78
  end
79
-
80
- # Error for Tools::Config#cluster
81
- class Cluster < RubyRabbitmqJanus::Errors::Tools::BaseConfig
82
- def initialize
83
- super 'Error for reading cluster enabled option', :fatal
84
- end
85
- end
86
-
87
- # Error for Tools::Config#number_of_instance
88
- class NumberOfinstance < RubyRabbitmqJanus::Errors::Tools::BaseConfig
89
- def initialize
90
- super 'Error for reading cluster instance count', :fatal
91
- end
92
- end
93
79
  end
94
80
  end
95
81
  end
@@ -31,6 +31,13 @@ module RubyRabbitmqJanus
31
31
  super "Error for test use current handle -- #{opts}", :fatal
32
32
  end
33
33
  end
34
+
35
+ # Error for Tools::Option#cluster_mode
36
+ class ClusterMode < RubyRabbitmqJanus::Errors::Tools::BaseOption
37
+ def initialize
38
+ super 'Error for create session in cluster mode disable', :fatal
39
+ end
40
+ end
34
41
  end
35
42
  end
36
43
  end
data/lib/rrj/info.rb CHANGED
@@ -6,7 +6,7 @@
6
6
  # Define constant to gem.
7
7
  module RubyRabbitmqJanus
8
8
  # Define version to gem
9
- VERSION = '2.1.1'
9
+ VERSION = '2.2.0'
10
10
 
11
11
  # Name to gem
12
12
  GEM_NAME = 'ruby_rabbitmq_janus'
data/lib/rrj/init.rb CHANGED
@@ -39,8 +39,6 @@ module RubyRabbitmqJanus
39
39
  # => #<RubyRabbitmqJanus::RRJ:0x007 @session=123>
40
40
  def initialize
41
41
  @option = Tools::Option.new
42
- ObjectSpace.define_finalizer(self, RRJ.method(:delete).to_proc) \
43
- unless File.basename($PROGRAM_NAME).eql?('rspec')
44
42
  rescue => error
45
43
  raise Errors::RRJ::InstanciateGem, error
46
44
  end
@@ -115,14 +113,5 @@ module RubyRabbitmqJanus
115
113
  private
116
114
 
117
115
  attr_reader :option
118
-
119
- def self.delete(_id)
120
- Tools::Cluster.instance.sessions.each do |janus_instance|
121
- array_ji = "#{janus_instance.instance},#{janus_instance.session}"
122
- `rake rrj:delete:one_instance[#{array_ji}]`
123
- end
124
- end
125
-
126
- private_class_method :delete
127
116
  end
128
117
  end
@@ -13,11 +13,10 @@ module RubyRabbitmqJanus
13
13
  class Concurrency
14
14
  # Initialize class with elements for thread communication
15
15
  def initialize
16
- Tools::Log.instance.info "Create an thread -- #{self.class.name}"
17
- @rabbit = Rabbit::Connect.new
16
+ Tools::Log.instance.info info_thread
17
+ @rabbit = RubyRabbitmqJanus::Rabbit::Connect.new
18
18
  @lock = Mutex.new
19
19
  @condition = ConditionVariable.new
20
- @thread = Thread.new { initialize_thread }
21
20
  rescue
22
21
  raise Errors::Janus::Concurencies::Initializer
23
22
  end
@@ -31,11 +30,15 @@ module RubyRabbitmqJanus
31
30
  @rabbit.close
32
31
  end
33
32
 
34
- attr_reader :thread, :lock, :condition, :rabbit
33
+ def info_thread
34
+ "Create an thread -- #{self.class.name}"
35
+ end
36
+
37
+ attr_reader :lock, :condition, :rabbit
35
38
  end
36
39
  end
37
40
  end
38
41
  end
39
42
 
40
- require 'rrj/janus/processus/keepalive'
43
+ require 'rrj/janus/processus/keepalive/keepalive_initializer'
41
44
  require 'rrj/janus/processus/event'
@@ -5,7 +5,7 @@ module RubyRabbitmqJanus
5
5
  module Concurrencies
6
6
  # @author VAILLANT Jeremy <jeremy.vaillant@dazzl.tv>
7
7
 
8
- # # Listen standar queue
8
+ # # Listen public queue to all Janus instance
9
9
  #
10
10
  # Listen standard queue and sending a block code to thread listen.
11
11
  # The default queue is configured in config file.
@@ -14,8 +14,9 @@ module RubyRabbitmqJanus
14
14
  class Event < Concurrency
15
15
  include Singleton
16
16
 
17
- def initalize
17
+ def initialize
18
18
  super
19
+ @thread = Thread.new { initialize_thread }
19
20
  rescue
20
21
  raise Errors::Janus::Event::Initializer
21
22
  end
@@ -28,9 +29,11 @@ module RubyRabbitmqJanus
28
29
  #
29
30
  # @return [Thread] It's a thread who listen queue and execute action
30
31
  def run(&block)
31
- thread.join
32
+ @thread.join
32
33
  Thread.new do
33
- loop { thread.thread_variable_get(:publish).listen_events(&block) }
34
+ loop do
35
+ @thread.thread_variable_get(:publish).listen_events(&block)
36
+ end
34
37
  end
35
38
  rescue
36
39
  raise Errors::Janus::Event::Run
@@ -40,7 +43,7 @@ module RubyRabbitmqJanus
40
43
 
41
44
  def transaction_running
42
45
  publisher = Rabbit::Publisher::Listener.new(rabbit)
43
- Thread.current.thread_variable_set(:publish, publisher)
46
+ @thread.thread_variable_set(:publish, publisher)
44
47
  end
45
48
  end
46
49
  end