ruby_rabbitmq_janus 2.0.0 → 2.1.0.pre.128

Sign up to get free protection for your applications and to get access to all the features.
Files changed (115) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +14 -3
  3. data/Rakefile +98 -0
  4. data/config/default.md +6 -3
  5. data/config/default.yml +7 -1
  6. data/lib/generators/ruby_rabbitmq_janus/install_generator.rb +3 -0
  7. data/lib/generators/ruby_rabbitmq_janus/migration_generator.rb +30 -0
  8. data/lib/generators/ruby_rabbitmq_janus/templates/migration.rb +14 -0
  9. data/lib/rrj/admin.rb +2 -0
  10. data/lib/rrj/errors/base/admin.rb +24 -0
  11. data/lib/rrj/errors/base/base.rb +5 -0
  12. data/lib/rrj/errors/base/init.rb +46 -0
  13. data/lib/rrj/errors/base/task.rb +32 -0
  14. data/lib/rrj/errors/error.rb +4 -3
  15. data/lib/rrj/errors/janus/janus.rb +20 -7
  16. data/lib/rrj/errors/janus/messages/admin.rb +33 -0
  17. data/lib/rrj/errors/janus/messages/message.rb +51 -0
  18. data/lib/rrj/errors/janus/messages/standard.rb +33 -0
  19. data/lib/rrj/errors/janus/processus/concurency.rb +23 -0
  20. data/lib/rrj/errors/janus/processus/event.rb +30 -0
  21. data/lib/rrj/errors/janus/processus/keepalive.rb +33 -0
  22. data/lib/rrj/errors/janus/responses/admin.rb +39 -0
  23. data/lib/rrj/errors/janus/responses/event.rb +46 -0
  24. data/lib/rrj/errors/janus/responses/response.rb +44 -0
  25. data/lib/rrj/errors/janus/responses/standard.rb +58 -0
  26. data/lib/rrj/errors/janus/transactions/admin.rb +37 -0
  27. data/lib/rrj/errors/janus/transactions/handle.rb +52 -0
  28. data/lib/rrj/errors/janus/transactions/session.rb +38 -0
  29. data/lib/rrj/errors/janus/transactions/transaction.rb +23 -0
  30. data/lib/rrj/errors/rabbit/connect.rb +58 -0
  31. data/lib/rrj/errors/rabbit/propertie.rb +37 -0
  32. data/lib/rrj/errors/rabbit/publish/admin.rb +30 -0
  33. data/lib/rrj/errors/rabbit/publish/base_publisher.rb +23 -0
  34. data/lib/rrj/errors/rabbit/publish/exclusive.rb +31 -0
  35. data/lib/rrj/errors/rabbit/publish/listener.rb +30 -0
  36. data/lib/rrj/errors/rabbit/publish/non_exclusive.rb +31 -0
  37. data/lib/rrj/errors/rabbit/publish/publisher.rb +30 -0
  38. data/lib/rrj/errors/rabbit/rabbit.rb +14 -23
  39. data/lib/rrj/errors/tools/gem/cluster.rb +44 -0
  40. data/lib/rrj/errors/tools/gem/config.rb +89 -0
  41. data/lib/rrj/errors/tools/gem/log.rb +86 -0
  42. data/lib/rrj/errors/tools/gem/option.rb +37 -0
  43. data/lib/rrj/errors/tools/gem/request.rb +23 -0
  44. data/lib/rrj/errors/tools/replaces/replace.rb +30 -0
  45. data/lib/rrj/errors/tools/replaces/type.rb +30 -0
  46. data/lib/rrj/errors/tools/tools.rb +21 -1
  47. data/lib/rrj/info.rb +1 -1
  48. data/lib/rrj/init.rb +22 -4
  49. data/lib/rrj/janus/messages/admin.rb +9 -4
  50. data/lib/rrj/janus/messages/message.rb +20 -9
  51. data/lib/rrj/janus/messages/standard.rb +8 -2
  52. data/lib/rrj/janus/processus/concurrency.rb +2 -0
  53. data/lib/rrj/janus/processus/event.rb +8 -0
  54. data/lib/rrj/janus/processus/keepalive.rb +15 -23
  55. data/lib/rrj/janus/responses/admin.rb +6 -0
  56. data/lib/rrj/janus/responses/event.rb +8 -0
  57. data/lib/rrj/janus/responses/response.rb +8 -11
  58. data/lib/rrj/janus/responses/standard.rb +12 -0
  59. data/lib/rrj/janus/transactions/admin.rb +6 -0
  60. data/lib/rrj/janus/transactions/handle.rb +25 -3
  61. data/lib/rrj/janus/transactions/session.rb +6 -0
  62. data/lib/rrj/janus/transactions/transaction.rb +3 -9
  63. data/lib/rrj/models/active_record.rb +14 -0
  64. data/lib/rrj/models/concerns/janus_instance_concern.rb +47 -0
  65. data/lib/rrj/models/mongoid.rb +19 -0
  66. data/lib/rrj/rabbit/connect.rb +12 -8
  67. data/lib/rrj/rabbit/propertie.rb +23 -6
  68. data/lib/rrj/rabbit/publish/admin.rb +4 -0
  69. data/lib/rrj/rabbit/publish/base_publisher.rb +2 -1
  70. data/lib/rrj/rabbit/publish/exclusive.rb +4 -0
  71. data/lib/rrj/rabbit/publish/listener.rb +6 -0
  72. data/lib/rrj/rabbit/publish/non_exclusive.rb +4 -0
  73. data/lib/rrj/rabbit/publish/publisher.rb +4 -4
  74. data/lib/rrj/railtie.rb +15 -0
  75. data/lib/rrj/task.rb +51 -0
  76. data/lib/rrj/tools/gem/cluster.rb +65 -0
  77. data/lib/rrj/tools/gem/config.rb +38 -6
  78. data/lib/rrj/tools/gem/log.rb +24 -4
  79. data/lib/rrj/tools/gem/option.rb +21 -17
  80. data/lib/rrj/tools/gem/requests.rb +11 -7
  81. data/lib/rrj/tools/replaces/replace.rb +4 -0
  82. data/lib/rrj/tools/replaces/type.rb +4 -0
  83. data/lib/rrj/tools/tools.rb +1 -0
  84. data/lib/ruby_rabbitmq_janus.rb +3 -0
  85. data/lib/tasks/delete_all_instance.rake +12 -0
  86. data/spec/request/admin/request_handle_info_spec.rb +4 -3
  87. data/spec/request/admin/request_handles_spec.rb +4 -3
  88. data/spec/request/peer/request_trickle_spec.rb +1 -1
  89. data/spec/rrj/rabbit/propertie_spec.rb +37 -2
  90. data/spec/rrj/tools/gem/rrj_cluster_spec.rb +26 -0
  91. data/spec/rrj/tools/gem/rrj_config_spec.rb +78 -0
  92. data/spec/rrj/tools/gem/rrj_log_spec.rb +55 -0
  93. data/spec/rrj/tools/{replace_admin_spec.rb → replace/replace_admin_spec.rb} +0 -0
  94. data/spec/rrj/tools/{replace_handle_spec.rb → replace/replace_handle_spec.rb} +0 -0
  95. data/spec/rrj/tools/{replace_session_spec.rb → replace/replace_session_spec.rb} +0 -0
  96. data/spec/rrj/tools/{replace_spec.rb → replace/replace_spec.rb} +0 -0
  97. data/spec/rrj/tools/{type_spec.rb → replace/type_spec.rb} +0 -0
  98. data/spec/spec_helper.rb +33 -2
  99. data/spec/support/examples_config.rb +10 -0
  100. data/spec/support/examples_message.rb +0 -2
  101. data/spec/support/examples_request.rb +4 -4
  102. data/spec/support/schemas/config/config.json +4 -2
  103. data/spec/support/schemas/config/rabbit_options.json +1 -1
  104. data/spec/support/schemas/config/rabbit_options2.json +13 -0
  105. data/spec/support/schemas/config/rabbit_options_admin.json +1 -1
  106. data/spec/support/schemas/config/rabbit_options_admin2.json +13 -0
  107. metadata +98 -17
  108. data/lib/rrj/errors/init.rb +0 -69
  109. data/lib/rrj/errors/janus/janus_message.rb +0 -53
  110. data/lib/rrj/errors/janus/janus_processus_keepalive.rb +0 -48
  111. data/lib/rrj/errors/janus/janus_response.rb +0 -89
  112. data/lib/rrj/errors/janus/janus_transaction.rb +0 -29
  113. data/lib/rrj/errors/tools/config.rb +0 -43
  114. data/spec/rrj/rrj_config_spec.rb +0 -67
  115. data/spec/rrj/rrj_log_spec.rb +0 -16
@@ -0,0 +1,86 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RubyRabbitmqJanus
4
+ module Errors
5
+ module Tools
6
+ # Define super class for all errors in Log class
7
+ class BaseLog < BaseTools
8
+ def initialize(message, level = :warn)
9
+ super("[Log] #{message}", level)
10
+ end
11
+ end
12
+
13
+ module Log
14
+ # Error for Tools::Log#initialize
15
+ class Initialize < RubyRabbitmqJanus::Errors::Tools::BaseLog
16
+ def initialize
17
+ super 'Error in initializer', :fatal
18
+ end
19
+ end
20
+
21
+ # Error for Tools::Log#unknow
22
+ class Unknow < RubyRabbitmqJanus::Errors::Tools::BaseLog
23
+ def initialize
24
+ super 'Error for writing in logger with level :unknown'
25
+ end
26
+ end
27
+
28
+ # Error for Tools::Log#fatal
29
+ class Fatal < RubyRabbitmqJanus::Errors::Tools::BaseLog
30
+ def initialize
31
+ super 'Error for writing in logger with level :fatal'
32
+ end
33
+ end
34
+
35
+ # Error for Tools::Log#error
36
+ class Error < RubyRabbitmqJanus::Errors::Tools::BaseLog
37
+ def initialize
38
+ super 'Error for writing in logger with level :error'
39
+ end
40
+ end
41
+
42
+ # Error for Tools::Log#warn
43
+ class Warn < RubyRabbitmqJanus::Errors::Tools::BaseLog
44
+ def initialize
45
+ super 'Error for writing in logger with level :warning'
46
+ end
47
+ end
48
+
49
+ # Error for Tools::Log#info
50
+ class Info < RubyRabbitmqJanus::Errors::Tools::BaseLog
51
+ def initialize
52
+ super 'Error for writing in logger with level :nfo'
53
+ end
54
+ end
55
+
56
+ # Error for Tools::Log#debug
57
+ class Debug < RubyRabbitmqJanus::Errors::Tools::BaseLog
58
+ def initialize
59
+ super 'Error for writing in logger with level :debug'
60
+ end
61
+ end
62
+
63
+ # Error for Tools::Log#logger
64
+ class Logger < RubyRabbitmqJanus::Errors::Tools::BaseLog
65
+ def initialize
66
+ super 'Error return logger to instance'
67
+ end
68
+ end
69
+
70
+ # Error for Tools::Log#logdev
71
+ class Logdev < RubyRabbitmqJanus::Errors::Tools::BaseLog
72
+ def initialize
73
+ super 'Error filname to logger instance'
74
+ end
75
+ end
76
+
77
+ # Error for Tools::Log#save_level
78
+ class SaveLevel < RubyRabbitmqJanus::Errors::Tools::BaseLog
79
+ def initialize
80
+ super 'Error for changing log level'
81
+ end
82
+ end
83
+ end
84
+ end
85
+ end
86
+ end
@@ -0,0 +1,37 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RubyRabbitmqJanus
4
+ module Errors
5
+ module Tools
6
+ # Define a super class for all error in Option class
7
+ class BaseOption < BaseTools
8
+ def initialize(message, level)
9
+ super("[Option] #{message}", level)
10
+ end
11
+ end
12
+
13
+ module Option
14
+ # Error for Tools::Option#initialize
15
+ class Initialize < RubyRabbitmqJanus::Errors::Tools::BaseOption
16
+ def initialize(msg)
17
+ super "Error in initializer : #{msg}", :fatal
18
+ end
19
+ end
20
+
21
+ # Error for Tools::Option#use_current_session?
22
+ class UseCurrentSession < RubyRabbitmqJanus::Errors::Tools::BaseOption
23
+ def initialize(opts)
24
+ super "Error for test use current session -- #{opts}", :fatal
25
+ end
26
+ end
27
+
28
+ # Error for Tools::Option#use_current_handle?
29
+ class UseCurrentHandle < RubyRabbitmqJanus::Errors::Tools::BaseOption
30
+ def initialize(opts)
31
+ super "Error for test use current handle -- #{opts}", :fatal
32
+ end
33
+ end
34
+ end
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,23 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RubyRabbitmqJanus
4
+ module Errors
5
+ module Tools
6
+ # Define super class for all errors in request class
7
+ class BaseRequest < BaseTools
8
+ def initialize(message, level = :fatal)
9
+ super("[Request] #{message}", level)
10
+ end
11
+ end
12
+
13
+ module Request
14
+ # Error initialize method for Request class
15
+ class Initializer < RubyRabbitmqJanus::Errors::Tools::BaseRequest
16
+ def initalize
17
+ super 'Error in initializer'
18
+ end
19
+ end
20
+ end
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,30 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RubyRabbitmqJanus
4
+ module Errors
5
+ module Tools
6
+ # Super class error for Replace class
7
+ class BaseReplace < BaseTools
8
+ def initialize(message, level = :fatal)
9
+ super "[Replace] #{message}", level
10
+ end
11
+ end
12
+
13
+ module Replace
14
+ # Error for initialize in Replace class
15
+ class Initialize < RubyRabbitmqJanus::Errors::Tools::BaseReplace
16
+ def initialize
17
+ super 'Error in initializer'
18
+ end
19
+ end
20
+
21
+ # Error for transform_request in Replace class
22
+ class TransformRequest < RubyRabbitmqJanus::Errors::Tools::BaseReplace
23
+ def initialize
24
+ super 'Error for transform base request element'
25
+ end
26
+ end
27
+ end
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,30 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RubyRabbitmqJanus
4
+ module Errors
5
+ module Tools
6
+ # Super class error for Type class
7
+ class BaseType < BaseTools
8
+ def initialize(message, level = :fatal)
9
+ super "[Type] #{message}", level
10
+ end
11
+ end
12
+
13
+ module Type
14
+ # Error for initialize method in Type class
15
+ class Initialize < RubyRabbitmqJanus::Errors::Tools::BaseType
16
+ def initialize
17
+ super 'Error in initializer'
18
+ end
19
+ end
20
+
21
+ # Error for convert method in Type class
22
+ class Convert < RubyRabbitmqJanus::Errors::Tools::BaseType
23
+ def initialize
24
+ super 'Error for converting data to good type'
25
+ end
26
+ end
27
+ end
28
+ end
29
+ end
30
+ end
@@ -1,3 +1,23 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'rrj/errors/tools/config'
3
+ module RubyRabbitmqJanus
4
+ module Errors
5
+ module Tools
6
+ # Define a super class for all error in Option class
7
+ class BaseTools < RRJError
8
+ def initialize(message, level = :fatal)
9
+ super("[Tools]#{message}", level)
10
+ end
11
+ end
12
+ end
13
+ end
14
+ end
15
+
16
+ require 'rrj/errors/tools/gem/cluster'
17
+ require 'rrj/errors/tools/gem/config'
18
+ require 'rrj/errors/tools/gem/log'
19
+ require 'rrj/errors/tools/gem/option'
20
+ require 'rrj/errors/tools/gem/request'
21
+
22
+ require 'rrj/errors/tools/replaces/replace'
23
+ require 'rrj/errors/tools/replaces/type'
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.0.0'
9
+ VERSION = '2.1.0'
10
10
 
11
11
  # Name to gem
12
12
  GEM_NAME = 'ruby_rabbitmq_janus'
data/lib/rrj/init.rb CHANGED
@@ -10,6 +10,8 @@ require 'key_path'
10
10
  require 'active_support'
11
11
  require 'erb'
12
12
 
13
+ # :reek:TooManyStatements
14
+
13
15
  # Primary module for this gem
14
16
  module RubyRabbitmqJanus
15
17
  # @author VAILLANT Jeremy <jeremy.vaillant@dazzl.tv>
@@ -37,10 +39,8 @@ module RubyRabbitmqJanus
37
39
  # => #<RubyRabbitmqJanus::RRJ:0x007 @session=123>
38
40
  def initialize
39
41
  @option = Tools::Option.new
40
- @session = @option.keepalive
41
- Tools::Log.instance.info "Create an session janus with id : #{@session}"
42
42
  rescue => error
43
- raise Errors::InstanciateGemFailed, error
43
+ raise Errors::RRJ::InstanciateGem, error
44
44
  end
45
45
 
46
46
  # Start a transaction with Janus. Request use session_id information.
@@ -59,6 +59,8 @@ module RubyRabbitmqJanus
59
59
  session = @option.use_current_session?(options)
60
60
  transaction = Janus::Transactions::Session.new(exclusive, session)
61
61
  transaction.connect { yield(transaction) }
62
+ rescue
63
+ raise Errors::RRJ::StartTransaction.new(exclusive, options)
62
64
  end
63
65
 
64
66
  # Start a transaction with Janus. Request used session_id/handle_id
@@ -88,8 +90,24 @@ module RubyRabbitmqJanus
88
90
  def start_transaction_handle(exclusive = true, options = {})
89
91
  session = @option.use_current_session?(options)
90
92
  handle = @option.use_current_handle?(options)
91
- transaction = Janus::Transactions::Handle.new(exclusive, session, handle)
93
+ instance = options['instance'] || 1
94
+ transaction = Janus::Transactions::Handle.new(exclusive,
95
+ session,
96
+ handle,
97
+ instance)
92
98
  transaction.connect { yield(transaction) }
99
+ rescue
100
+ raise Errors::RRJ::StartTransactionHandle, exclusive, options
101
+ end
102
+
103
+ # Delete all resources to JanusInstance reference.
104
+ # Warning: All data in database and Janus Instance is delete
105
+ #
106
+ # @since 2.1.0
107
+ def cleanup_connection
108
+ Models::JanusInstance.destroys
109
+ rescue
110
+ raise Errors::RRJ::CleanupConnection
93
111
  end
94
112
 
95
113
  private
@@ -7,12 +7,17 @@ module RubyRabbitmqJanus
7
7
  #
8
8
  # Create an message for janus
9
9
  class Admin < Message
10
+ def initialize(template_request, options = {})
11
+ super(template_request, options)
12
+ rescue
13
+ raise Errors::Janus::MessageAdmin::Initializer
14
+ end
15
+
10
16
  # Return options to message for rabbitmq
11
17
  def options
12
- Tools::Log.instance.debug 'Options used for admin message'
13
- properties.options_admin
14
- rescue => error
15
- raise Errors::JanusMessagePropertie, error
18
+ properties.options_admin(type)
19
+ rescue
20
+ raise Errors::Janus::MessageAdmin::Options
16
21
  end
17
22
 
18
23
  private
@@ -40,14 +40,15 @@ module RubyRabbitmqJanus
40
40
  # "add": {
41
41
  # "subtitle": true
42
42
  # })
43
+ # def initialize(template_request, options = { 'instance' => 1 })
43
44
  def initialize(template_request, options = {})
44
45
  @request = {}
45
46
  @type = template_request
46
- @properties = Rabbit::Propertie.new
47
+ @properties = Rabbit::Propertie.new(options['instance'])
47
48
  load_request_file
48
49
  prepare_request(options)
49
- rescue => error
50
- raise Errors::JanusMessage, error
50
+ rescue
51
+ raise Errors::Janus::Message::Initializer
51
52
  end
52
53
 
53
54
  # Return request to json format
@@ -55,8 +56,8 @@ module RubyRabbitmqJanus
55
56
  # @return [String] Request to JSON format
56
57
  def to_json
57
58
  @request.to_json
58
- rescue => error
59
- raise Errors::JanusMessageJson, error
59
+ rescue
60
+ raise Errors::Janus::Message::ToJson
60
61
  end
61
62
 
62
63
  # Return request to json format with nice format
@@ -64,8 +65,8 @@ module RubyRabbitmqJanus
64
65
  # @return [String] Request to JSON format with indent
65
66
  def to_nice_json
66
67
  JSON.pretty_generate to_hash
67
- rescue => error
68
- raise Errors::JanusMessagePrettyJson, error
68
+ rescue
69
+ raise Errors::Janus::Message::ToNiceJson
69
70
  end
70
71
 
71
72
  # Return request to hash format
@@ -73,8 +74,8 @@ module RubyRabbitmqJanus
73
74
  # @return [Hash] Request to Hash format
74
75
  def to_hash
75
76
  @request
76
- rescue => error
77
- raise Errors::JanusMessageHash, error
77
+ rescue
78
+ raise Errors::Janus::Message::ToHash
78
79
  end
79
80
 
80
81
  # Return correlation to message
@@ -82,6 +83,8 @@ module RubyRabbitmqJanus
82
83
  # @return [String] Correlation string
83
84
  def correlation
84
85
  @properties.correlation
86
+ rescue
87
+ raise Errors::Janus::Message::Correlation
85
88
  end
86
89
 
87
90
  private
@@ -100,6 +103,14 @@ module RubyRabbitmqJanus
100
103
  def request_instance
101
104
  JSON.parse File.read Tools::Requests.instance.requests[@type]
102
105
  end
106
+
107
+ def find_instance(options)
108
+ if options.key?('instance')
109
+ options['instance']
110
+ else
111
+ Models::JanusInstance.find_by_session(options['session_id'])
112
+ end
113
+ end
103
114
  end
104
115
  end
105
116
  end
@@ -7,11 +7,17 @@ module RubyRabbitmqJanus
7
7
  #
8
8
  # # Create an standard message
9
9
  class Standard < Message
10
+ def initialize(template_request, options = {})
11
+ super(template_request, options)
12
+ rescue
13
+ raise Errors::Janus::MessageStandard::Initializer
14
+ end
15
+
10
16
  # Return options to message for rabbitmq
11
17
  def options
12
18
  properties.options
13
- rescue => error
14
- raise Errors::JanusMessagePropertie, error
19
+ rescue
20
+ raise Errors::Janus::MessageStandard::Options
15
21
  end
16
22
 
17
23
  private
@@ -18,6 +18,8 @@ module RubyRabbitmqJanus
18
18
  @lock = Mutex.new
19
19
  @condition = ConditionVariable.new
20
20
  @thread = Thread.new { initialize_thread }
21
+ rescue
22
+ raise Errors::Janus::Concurencies::Initializer
21
23
  end
22
24
 
23
25
  private
@@ -14,6 +14,12 @@ module RubyRabbitmqJanus
14
14
  class Event < Concurrency
15
15
  include Singleton
16
16
 
17
+ def initalize
18
+ super
19
+ rescue
20
+ raise Errors::Janus::Event::Initializer
21
+ end
22
+
17
23
  # Create a thread for execute a block code in a thread
18
24
  #
19
25
  # @param [Proc] block Block code for execute action when queue
@@ -26,6 +32,8 @@ module RubyRabbitmqJanus
26
32
  Thread.new do
27
33
  loop { thread.thread_variable_get(:publish).listen_events(&block) }
28
34
  end
35
+ rescue
36
+ raise Errors::Janus::Event::Run
29
37
  end
30
38
 
31
39
  private