ruby_rabbitmq_janus 2.1.0.pre.130 → 2.1.0.pre.131
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +6 -0
- data/lib/generators/ruby_rabbitmq_janus/configuration_generator.rb +1 -11
- data/lib/generators/ruby_rabbitmq_janus/default_request_generator.rb +1 -11
- data/lib/generators/ruby_rabbitmq_janus/initializer_generator.rb +2 -21
- data/lib/generators/ruby_rabbitmq_janus/install_generator.rb +5 -26
- data/lib/generators/ruby_rabbitmq_janus/templates/actions.rb +22 -0
- data/lib/generators/ruby_rabbitmq_janus/templates/initializer.rb +29 -0
- data/lib/rrj/errors/janus/transactions/transaction.rb +1 -1
- data/lib/rrj/init.rb +10 -0
- data/lib/rrj/janus/transactions/session.rb +3 -3
- data/lib/rrj/models/concerns/janus_instance_concern.rb +15 -1
- data/lib/rrj/task.rb +1 -1
- data/lib/rrj/tools/gem/cluster.rb +1 -1
- data/lib/tasks/delete_all_instance.rake +7 -5
- data/lib/tasks/delete_one_instance.rake +18 -0
- data/lib/tasks/delete_unless_instance.rake +14 -0
- data/spec/rrj/models/active_record_spec.rb +20 -0
- data/spec/rrj/models/mongoid_spec.rb +28 -0
- metadata +22 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 811e021180e0a35a51ba2ff75163625140382e7d
|
4
|
+
data.tar.gz: b1f5f2ad5d3cd7ed34ada499fdb471d31956854c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e2fe3d01287875d2a843831ecad3a0286d553f8253aadc984c187d8953a43e0926c118d75a80c6ac3a801e08ca4ec02164639fc4297e8638cea9943489573e9e
|
7
|
+
data.tar.gz: 914cd24efdf27e8aaabf4a7b82c24a5b7779a8b1dc1da1569abca51da080178329d2cfa1f2c41c242e583b103b12cb8e820bf16f0ad669ebacca0bd9954d99d4
|
data/README.md
CHANGED
@@ -80,6 +80,12 @@ Or install it yourself as :
|
|
80
80
|
gem install ruby_rabbitmq_janus
|
81
81
|
```
|
82
82
|
|
83
|
+
Install basic configuration :
|
84
|
+
|
85
|
+
```linux
|
86
|
+
rails g ruby_rabbitmq_janus:install
|
87
|
+
```
|
88
|
+
|
83
89
|
### Configuration
|
84
90
|
|
85
91
|
If you want used a customize configuration see [ruby-rabbitmq-janus.yml](config/default.md)
|
@@ -8,22 +8,12 @@ module RubyRabbitmqJanus
|
|
8
8
|
desc 'Generate a custom configuration file.'
|
9
9
|
|
10
10
|
# Define root path for original file a copied
|
11
|
-
|
12
|
-
root_path = File.realpath(root_path_gem)
|
13
|
-
@_rrj_source_root ||= File.join(root_path, 'config')
|
14
|
-
end
|
11
|
+
source_root File.expand_path('../../../config', __dir__)
|
15
12
|
|
16
13
|
# Copy a default configuration in config folder to Rails app
|
17
14
|
def copy_configuration
|
18
15
|
template 'default.yml', 'config/ruby-rabbitmq-janus.yml'
|
19
16
|
end
|
20
|
-
|
21
|
-
private
|
22
|
-
|
23
|
-
# Define a root path
|
24
|
-
def root_path_gem
|
25
|
-
File.join(File.dirname(__FILE__), '..', '..', '..')
|
26
|
-
end
|
27
17
|
end
|
28
18
|
end
|
29
19
|
end
|
@@ -7,22 +7,12 @@ module RubyRabbitmqJanus
|
|
7
7
|
desc 'Copy base request file sending to janus in application.'
|
8
8
|
|
9
9
|
# Define root path for original file a copied
|
10
|
-
|
11
|
-
root_path = File.realpath(root_path_gem)
|
12
|
-
@_rrj_source_root ||= File.join(root_path, 'config')
|
13
|
-
end
|
10
|
+
source_root File.expand_path('../../../config', __dir__)
|
14
11
|
|
15
12
|
# Copy default request in Rails app
|
16
13
|
def copy_default_request
|
17
14
|
directory 'requests', 'config/requests'
|
18
15
|
end
|
19
|
-
|
20
|
-
private
|
21
|
-
|
22
|
-
# Define a root path
|
23
|
-
def root_path_gem
|
24
|
-
File.join(File.dirname(__FILE__), '..', '..', '..')
|
25
|
-
end
|
26
16
|
end
|
27
17
|
end
|
28
18
|
end
|
@@ -5,31 +5,12 @@ module RubyRabbitmqJanus
|
|
5
5
|
# Create an class for generate a initializer
|
6
6
|
class InitializerGenerator < Rails::Generators::Base
|
7
7
|
desc 'Generate a initializer to this gem for rails application.'
|
8
|
-
INITIALIZER = <<-INIT
|
9
|
-
# frozen_string_literal: true
|
10
8
|
|
11
|
-
|
12
|
-
|
13
|
-
# Initialize a gem and create an session with a keepalive
|
14
|
-
::RRJ = RubyRabbitmqJanus::RRJ.new
|
15
|
-
|
16
|
-
# For admin management
|
17
|
-
# ::RRJ = RubyRabbitmqJanus::RRJAdmin.new
|
18
|
-
|
19
|
-
# This test disable this gems execution when you running an task with rake
|
20
|
-
unless File.basename($PROGRAM_NAME) == 'rake'
|
21
|
-
Rails.configuration.after_initialize do
|
22
|
-
# If you don't want listen a standard queue, comment this lines and
|
23
|
-
# "require 'actions'"
|
24
|
-
actions = RubyRabbitmqJanus::ActionEvents.new.actions
|
25
|
-
RubyRabbitmqJanus::Janus::Concurrencies::Event.instance.run(&actions)
|
26
|
-
end
|
27
|
-
end
|
28
|
-
INIT
|
9
|
+
source_root File.expand_path('../templates', __FILE__)
|
29
10
|
|
30
11
|
# Create an initializer
|
31
12
|
def copy_initializer
|
32
|
-
initializer 'ruby_rabbitmq_janus.rb'
|
13
|
+
copy_file 'initializer.rb', 'config/initializers/ruby_rabbitmq_janus.rb'
|
33
14
|
end
|
34
15
|
end
|
35
16
|
end
|
@@ -5,42 +5,21 @@ module RubyRabbitmqJanus
|
|
5
5
|
# Create an class for generate a installing
|
6
6
|
class InstallGenerator < Rails::Generators::Base
|
7
7
|
desc 'Install RubyRabbitmqJanus in your Rails application'
|
8
|
-
ACTION_CLASS = <<-BASE
|
9
|
-
module RubyRabbitmqJanus
|
10
|
-
# Execute this code when janus return an events in standard queue
|
11
|
-
class ActionsEvents
|
12
|
-
# Default method using for sending a block of code
|
13
|
-
def actions
|
14
|
-
lambda do |reason, data|
|
15
|
-
Rails.logger.debug "Execute block code with reason : \#{reason}"
|
16
|
-
case reason
|
17
|
-
when event this case_events(data.to_hash)
|
18
|
-
end
|
19
|
-
end
|
20
|
-
end
|
21
|
-
|
22
|
-
private
|
23
8
|
|
24
|
-
def case_events(data)
|
25
|
-
Rails.logger.debug "Event : \#{data}"
|
26
|
-
end
|
27
|
-
end
|
28
|
-
end
|
29
|
-
BASE
|
30
9
|
APPLICATION = <<-AUTOLOAD
|
31
10
|
# Load RubyRabbitmqJanus actions events code blocks
|
32
11
|
config.autoload_paths += Dir[Rails.root.join('app', 'ruby_rabbitmq_janus')]
|
33
12
|
AUTOLOAD
|
34
13
|
|
35
|
-
|
14
|
+
source_root File.expand_path('../templates', __FILE__)
|
15
|
+
|
16
|
+
# Generate files with default code
|
36
17
|
def add_actions
|
37
18
|
# Create an class
|
38
|
-
|
19
|
+
template 'actions.rb', 'app/ruby_rabbitmq_janus/actions.rb'
|
39
20
|
|
40
21
|
# Add to application.rb
|
41
|
-
application
|
42
|
-
APPLICATION
|
43
|
-
end
|
22
|
+
application { APPLICATION }
|
44
23
|
|
45
24
|
# Add initializer
|
46
25
|
generate 'ruby_rabbitmq_janus:initializer'
|
@@ -0,0 +1,22 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module RubyRabbitmqJanus
|
4
|
+
# Execute this code when janus return an events in standard queue
|
5
|
+
class ActionEvents
|
6
|
+
# Default method using for sending a block of code
|
7
|
+
def actions
|
8
|
+
lambda do |reason, data|
|
9
|
+
Rails.logger.debug "Execute block code with reason : #{reason}"
|
10
|
+
case reason
|
11
|
+
when event then case_events(data.to_hash)
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
private
|
17
|
+
|
18
|
+
def case_events(data)
|
19
|
+
Rails.logger.debug "Event : #{data}"
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# This test disable this gems execution when you running an task with rake
|
4
|
+
if File.basename($PROGRAM_NAME) == 'rake'
|
5
|
+
# Configure RRJ for rake task
|
6
|
+
::RRJ = RubyRabbitmqJanus::RRJTask.new
|
7
|
+
else
|
8
|
+
# Loading classes Actions to rails application
|
9
|
+
require 'actions'
|
10
|
+
|
11
|
+
# If you used gem config for manage your ENV variables uncomment this line
|
12
|
+
# @see https://rubygems.org/gems/config
|
13
|
+
# Settings.reload!
|
14
|
+
|
15
|
+
# Initialize gem and create a number of session by Janus instance.
|
16
|
+
::RRJ = RubyRabbitmqJanus::RRJ.new
|
17
|
+
|
18
|
+
# Use this initializer if your application use 'Admin/Monitor API'
|
19
|
+
# @see https://janus.conf.meetecho.com/docs/admin.html
|
20
|
+
# ::RRJ = RubyRabbitmqJanus::RRJAdmin.new
|
21
|
+
|
22
|
+
# Send a block code to thread for manage event given by Janus in public queue
|
23
|
+
Rails.configuration.after_initialize do
|
24
|
+
# If you don't want listen a standard queue, comment this block and
|
25
|
+
# "require 'actions'" also
|
26
|
+
actions = RubyRabbitmqJanus::ActionEvents.new.actions
|
27
|
+
RubyRabbitmqJanus::Janus::Concurrencies::Event.instance.run(&actions)
|
28
|
+
end
|
29
|
+
end
|
@@ -6,7 +6,7 @@ module RubyRabbitmqJanus
|
|
6
6
|
# Define a super class for all errors in Janus::Transactions::Transaction
|
7
7
|
class BaseTransaction < BaseJanus
|
8
8
|
def initialize(message, level = :fatal)
|
9
|
-
super "[Transaction]
|
9
|
+
super "[Transaction]#{message}", level
|
10
10
|
end
|
11
11
|
end
|
12
12
|
|
data/lib/rrj/init.rb
CHANGED
@@ -39,6 +39,7 @@ 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)
|
42
43
|
rescue => error
|
43
44
|
raise Errors::RRJ::InstanciateGem, error
|
44
45
|
end
|
@@ -113,5 +114,14 @@ module RubyRabbitmqJanus
|
|
113
114
|
private
|
114
115
|
|
115
116
|
attr_reader :option
|
117
|
+
|
118
|
+
def self.delete(_id)
|
119
|
+
Tools::Cluster.instance.sessions.each do |janus_instance|
|
120
|
+
array_ji = "#{janus_instance.instance},#{janus_instance.session}"
|
121
|
+
`rake rrj:delete:one_instance[#{array_ji}]`
|
122
|
+
end
|
123
|
+
end
|
124
|
+
|
125
|
+
private_class_method :delete
|
116
126
|
end
|
117
127
|
end
|
@@ -17,7 +17,7 @@ module RubyRabbitmqJanus
|
|
17
17
|
super(session)
|
18
18
|
@exclusive = exclusive
|
19
19
|
rescue
|
20
|
-
raise Errors::Janus::
|
20
|
+
raise Errors::Janus::TransactionSessions::Initialize
|
21
21
|
end
|
22
22
|
|
23
23
|
# Opening a short transaction with rabbitmq and close when is ending
|
@@ -29,7 +29,7 @@ module RubyRabbitmqJanus
|
|
29
29
|
yield
|
30
30
|
end
|
31
31
|
rescue
|
32
|
-
raise Errors::Janus::
|
32
|
+
raise Errors::Janus::TransactionSessions::Connect
|
33
33
|
end
|
34
34
|
|
35
35
|
def publish_message(type, options = {})
|
@@ -37,7 +37,7 @@ module RubyRabbitmqJanus
|
|
37
37
|
response = read_response(publisher.publish(msg))
|
38
38
|
Janus::Responses::Standard.new(response)
|
39
39
|
rescue
|
40
|
-
raise Errors::Janus::
|
40
|
+
raise Errors::Janus::TransactionSessions::PublishMessage
|
41
41
|
end
|
42
42
|
|
43
43
|
private
|
@@ -11,7 +11,7 @@ module RubyRabbitmqJanus
|
|
11
11
|
# Send an action for destroying a session in Janus Gateway instance
|
12
12
|
def destroy_before_action
|
13
13
|
options = { 'session_id' => session, 'instance' => instance }
|
14
|
-
|
14
|
+
search_initializer(options) do |transaction|
|
15
15
|
transaction.publish_message('base::destroy', options)
|
16
16
|
end
|
17
17
|
end
|
@@ -42,6 +42,20 @@ module RubyRabbitmqJanus
|
|
42
42
|
nil
|
43
43
|
end
|
44
44
|
end
|
45
|
+
|
46
|
+
private
|
47
|
+
|
48
|
+
def search_initializer(options)
|
49
|
+
if File.basename($PROGRAM_NAME) == 'rake'
|
50
|
+
::RRJ.start_transaction(options) do |transaction|
|
51
|
+
yield(transaction)
|
52
|
+
end
|
53
|
+
else
|
54
|
+
::RRJ.start_transaction(true, options) do |transaction|
|
55
|
+
yield(transaction)
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
45
59
|
end
|
46
60
|
end
|
47
61
|
end
|
data/lib/rrj/task.rb
CHANGED
@@ -36,7 +36,7 @@ module RubyRabbitmqJanus
|
|
36
36
|
raise Errors::RRJ::StartTransaction.new(true, options)
|
37
37
|
end
|
38
38
|
|
39
|
-
# Create a transaction
|
39
|
+
# Create a transaction between apps and janus with a handle
|
40
40
|
#
|
41
41
|
# @since 2.1.0
|
42
42
|
def start_transaction_handle(exclusive = true, options = {})
|
@@ -1,12 +1,14 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
namespace :rrj do
|
4
|
-
|
5
|
-
|
6
|
-
|
4
|
+
namespace :delete do
|
5
|
+
desc 'Delete all instances in database and janus'
|
6
|
+
task all_instances: :environment do
|
7
|
+
timelaps = Time.now.utc
|
7
8
|
|
8
|
-
|
9
|
+
RubyRabbitmqJanus::Models::JanusInstance.destroy_all
|
9
10
|
|
10
|
-
|
11
|
+
Rails.logger.info "Executed in #{Time.now.utc - timelaps} ms"
|
12
|
+
end
|
11
13
|
end
|
12
14
|
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
namespace :rrj do
|
4
|
+
namespace :delete do
|
5
|
+
desc 'Delete one instance in database and janus'
|
6
|
+
task :one_instance, [:instance, :session] => :environment do |_task, args|
|
7
|
+
timelaps = Time.now.utc
|
8
|
+
|
9
|
+
Rails.logger.info \
|
10
|
+
"Delete instance #{args[:instance]} with session #{args[:session]}"
|
11
|
+
|
12
|
+
RubyRabbitmqJanus::Models::JanusInstance\
|
13
|
+
.find_by_session(args[:session]).destroy
|
14
|
+
|
15
|
+
Rails.logger.info "Executed in #{Time.now.utc - timelaps} ms"
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
namespace :rrj do
|
4
|
+
namespace :delete do
|
5
|
+
desc 'Delete all instances disable in database and janus'
|
6
|
+
task unless_instance: :environment do
|
7
|
+
timelaps = Time.now.utc
|
8
|
+
|
9
|
+
RubyRabbitmqJanus::Models::JanusInstance.find_by(enable: false).delete_all
|
10
|
+
|
11
|
+
Rails.logger.info "Executed in #{Time.now.utc - timelaps} ms"
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
describe RubyRabbitmqJanus::Models::JanusInstance, type: :model,
|
6
|
+
name: :janus_instance do
|
7
|
+
before do
|
8
|
+
Object.send(:remove_const, :Mongoid) if defined?(Mongoid)
|
9
|
+
require 'active_record' unless defined?(ActiveRecord::Core)
|
10
|
+
end
|
11
|
+
|
12
|
+
let(:model) { RubyRabbitmqJanus::Models::JanusInstance }
|
13
|
+
|
14
|
+
context 'active record model' do
|
15
|
+
it { expect(model.attribute_names).to include('id') }
|
16
|
+
it { expect(model.attribute_names).to include('instance') }
|
17
|
+
it { expect(model.attribute_names).to include('session') }
|
18
|
+
it { expect(model.attribute_names).to include('enable') }
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# rubocop:disable Style/ConstantName
|
4
|
+
|
5
|
+
require 'spec_helper'
|
6
|
+
|
7
|
+
describe RubyRabbitmqJanus::Models::JanusInstance, type: :model,
|
8
|
+
name: :janus_instance do
|
9
|
+
before do
|
10
|
+
ActiveRecord::Core = nil if defined?(ActiveRecord)
|
11
|
+
require 'mongoid' unless defined?(Mongoid)
|
12
|
+
end
|
13
|
+
|
14
|
+
context 'mongoid model' do
|
15
|
+
let(:model) { RubyRabbitmqJanus::Models::JanusInstance }
|
16
|
+
|
17
|
+
it { expect(model.attribute_names).to include('id') }
|
18
|
+
it { expect(model.attribute_names).to include('instance') }
|
19
|
+
it { expect(model.attribute_names).to include('session') }
|
20
|
+
it { expect(model.attribute_names).to include('enable') }
|
21
|
+
end
|
22
|
+
|
23
|
+
after do
|
24
|
+
Object.send(:remove_const, :Mongoid) if defined?(Mongoid)
|
25
|
+
require 'active_record' unless defined?(ActiveRecord)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
# rubocop:enable Style/ConstantName
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ruby_rabbitmq_janus
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.1.0.pre.
|
4
|
+
version: 2.1.0.pre.131
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- VAILLANT Jeremy
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-06-
|
11
|
+
date: 2017-06-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -248,6 +248,20 @@ dependencies:
|
|
248
248
|
- - "~>"
|
249
249
|
- !ruby/object:Gem::Version
|
250
250
|
version: '1.3'
|
251
|
+
- !ruby/object:Gem::Dependency
|
252
|
+
name: mongoid
|
253
|
+
requirement: !ruby/object:Gem::Requirement
|
254
|
+
requirements:
|
255
|
+
- - "~>"
|
256
|
+
- !ruby/object:Gem::Version
|
257
|
+
version: '5.2'
|
258
|
+
type: :development
|
259
|
+
prerelease: false
|
260
|
+
version_requirements: !ruby/object:Gem::Requirement
|
261
|
+
requirements:
|
262
|
+
- - "~>"
|
263
|
+
- !ruby/object:Gem::Version
|
264
|
+
version: '5.2'
|
251
265
|
- !ruby/object:Gem::Dependency
|
252
266
|
name: bunny
|
253
267
|
requirement: !ruby/object:Gem::Requirement
|
@@ -348,6 +362,8 @@ files:
|
|
348
362
|
- lib/generators/ruby_rabbitmq_janus/initializer_generator.rb
|
349
363
|
- lib/generators/ruby_rabbitmq_janus/install_generator.rb
|
350
364
|
- lib/generators/ruby_rabbitmq_janus/migration_generator.rb
|
365
|
+
- lib/generators/ruby_rabbitmq_janus/templates/actions.rb
|
366
|
+
- lib/generators/ruby_rabbitmq_janus/templates/initializer.rb
|
351
367
|
- lib/generators/ruby_rabbitmq_janus/templates/migration.rb
|
352
368
|
- lib/rrj/admin.rb
|
353
369
|
- lib/rrj/errors/base/admin.rb
|
@@ -431,6 +447,8 @@ files:
|
|
431
447
|
- lib/rrj/tools/tools.rb
|
432
448
|
- lib/ruby_rabbitmq_janus.rb
|
433
449
|
- lib/tasks/delete_all_instance.rake
|
450
|
+
- lib/tasks/delete_one_instance.rake
|
451
|
+
- lib/tasks/delete_unless_instance.rake
|
434
452
|
- spec/request/admin/request_handle_info_spec.rb
|
435
453
|
- spec/request/admin/request_handles_spec.rb
|
436
454
|
- spec/request/admin/request_sessions_spec.rb
|
@@ -449,6 +467,8 @@ files:
|
|
449
467
|
- spec/rrj/messages/messages_admin_spec.rb
|
450
468
|
- spec/rrj/messages/messages_message_spec.rb
|
451
469
|
- spec/rrj/messages/messages_standard_spec.rb
|
470
|
+
- spec/rrj/models/active_record_spec.rb
|
471
|
+
- spec/rrj/models/mongoid_spec.rb
|
452
472
|
- spec/rrj/rabbit/connect_spec.rb
|
453
473
|
- spec/rrj/rabbit/propertie_spec.rb
|
454
474
|
- spec/rrj/rabbit/publish/admin_spec.rb
|