ruby_rabbitmq_janus 2.7.2.pre.320 → 2.7.2.pre.322

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: fc50ee1b1b5ce39634a85050510221684d78a68cfb08947ae5e51ba60a492e3e
4
- data.tar.gz: 3e95da4477afa9df8370611da6f25bae324770924d5a843727f0ad1b2af42e64
3
+ metadata.gz: 38a584eadb729b97490abc2a5112886e14f4c5fa21ea3b9641411666c7f5c6ff
4
+ data.tar.gz: 93ad2a7f89b20edd383cb55097e98a060185268ad4b5564452c3679496a0f0c4
5
5
  SHA512:
6
- metadata.gz: 1ec90884318b4edc421e7dd6bdf7de960001024f5f3179e09ac16787bb5ff6255165a644de050fd6ca90debf65cbea8c5295fa104a4a926084aa2b9db55915e6
7
- data.tar.gz: 7af37d040a30723f419c992252d554f39ce85f19cfda389a1f652156422af9751706df12f9f92b49d8e5120a70c5b5fb5a31834731c5bc81be025c7e79cf806b
6
+ metadata.gz: 46aa8f7efdf93c442f5b350f28765d1041e6c4288f6ccd65ae85afe32a0f477b2c7fe9fc765e2f7a487b0efd381e53716d7be810543f962254223cd3297c835f
7
+ data.tar.gz: 2276a53735d1691dc3b54232ccacb4fd06d7f9760d788611cd19a2376316a64ae5af0f39b3594d674c020383765ad7cd15ea0f129892b3d1cca2f451109c29d7
data/README.md CHANGED
@@ -150,7 +150,7 @@ require 'ruby_rabbitmq_janus'
150
150
  actions = RubyRabbitmqJanus::ActionEvents.new.action
151
151
 
152
152
  # Initialize a thread for listen public queue and send class to thread
153
- RubyRabbitmqJanus::Janus::Concurrencies::Event.instance.run(@actions)
153
+ RubyRabbitmqJanus::Janus::Concurrencies::Event.new.run(@actions)
154
154
  ```
155
155
 
156
156
  ## Upgrade
@@ -42,6 +42,7 @@ gem:
42
42
  environment: 'development'
43
43
  orm: 'mongoid'
44
44
  response_path: 'spec/supports/rrj/responses'
45
+ process: 1
45
46
  ```
46
47
 
47
48
  ## Customize
@@ -78,3 +78,5 @@ gem:
78
78
  orm: 'mongoid'
79
79
  # Read response json for RSpec
80
80
  response_path: 'spec/supports/rrj/responses'
81
+ # Number ofprocess read public queue
82
+ process: 1
@@ -72,6 +72,6 @@ Settings.reload!
72
72
  # If you don't want listen a standard queue, comment this block and
73
73
  # "require 'actions'" also
74
74
  act = RubyRabbitmqJanus::ActionEvents.new.actions
75
- RubyRabbitmqJanus::Janus::Concurrencies::Event.instance.run(&act)
75
+ RubyRabbitmqJanus::Janus::Concurrencies::Event.new.run(&act)
76
76
  end
77
77
  end
@@ -4,12 +4,13 @@
4
4
 
5
5
  # Fields for JanusInstance model
6
6
  class CreateRubyRabbitmqJanusTables < ActiveRecord::Migration[5.0]
7
+ # Change for model JanusInstance
7
8
  def change
8
9
  create_table :janus_instances, id: false, force: true do |table|
9
10
  table.string :id, null: false
11
+ table.string :name
10
12
  table.integer :session, limit: 8
11
13
  table.boolean :enable
12
- table.integer :thread, limit: 8
13
14
  end
14
15
  end
15
16
  end
@@ -5,6 +5,7 @@
5
5
  module RubyRabbitmqJanus
6
6
  module Errors
7
7
  module Rabbit
8
+ # Error class for all Event
8
9
  class Event < BaseRabbit
9
10
  def initialize(message, level = :fatal)
10
11
  super("[Connect] #{message}", level)
@@ -12,6 +13,7 @@ module RubyRabbitmqJanus
12
13
  end
13
14
 
14
15
  module BaseEvent
16
+ # Error class for Rabbit BaseEvent
15
17
  class Initialize < RubyRabbitmqJanus::Errors::Rabbit::Event
16
18
  def initialize
17
19
  super 'Error in intializer BaseEvent'
@@ -18,11 +18,9 @@ require 'rrj/errors/rabbit/propertie'
18
18
  require 'rrj/errors/rabbit/listener/base'
19
19
  require 'rrj/errors/rabbit/listener/from'
20
20
  require 'rrj/errors/rabbit/listener/from_admin'
21
- require 'rrj/errors/rabbit/listener/janus_instance'
22
21
 
23
22
  require 'rrj/errors/rabbit/publisher/base'
24
23
  require 'rrj/errors/rabbit/publisher/admin'
25
24
  require 'rrj/errors/rabbit/publisher/exclusive'
26
- require 'rrj/errors/rabbit/publisher/janus_instance'
27
25
  require 'rrj/errors/rabbit/publisher/keepalive'
28
26
  require 'rrj/errors/rabbit/publisher/non_exclusive'
@@ -14,46 +14,59 @@ module RubyRabbitmqJanus
14
14
  "#{type.gsub('::', '_')}.json")
15
15
  end
16
16
 
17
+ # Read response json file
17
18
  def read
18
19
  JSON.parse(File.read(@json))
19
20
  end
20
21
 
22
+ # Create fake session number
21
23
  def session
22
24
  (rand * 1_000_000).to_i
23
25
  end
24
26
 
27
+ # Read plugindata field
25
28
  def plugin
26
29
  read['plugindata']
27
30
  end
28
31
 
32
+ # Read data to plugindata field
29
33
  def plugin_data
30
34
  read['plugindata']['data']
31
35
  end
32
36
 
37
+ # Read data dield
33
38
  def data
34
39
  read['data']
35
40
  end
36
41
 
42
+ # Read sdp
37
43
  def sdp
38
44
  read['jsep']
39
45
  end
40
46
 
47
+ # Read sessions field
41
48
  def sessions
42
49
  read['sessions']
43
50
  end
44
51
 
52
+ # Read info field
45
53
  def info
46
54
  read['info']
47
55
  end
48
56
 
57
+ # Read fake keys
49
58
  def keys
50
59
  [546_321_963, 546_321_966]
51
60
  end
52
61
 
62
+ # Read first Janusinstance in database
53
63
  def instance
54
64
  JanusInstance.first
55
65
  end
56
66
 
67
+ # Read fake status to instance
68
+ #
69
+ # @return [Boolean] Random value
57
70
  def enable
58
71
  [True, False].sample
59
72
  end
@@ -7,16 +7,21 @@ module RubyRabbitmqJanus
7
7
  class RSpec
8
8
  attr_reader :response
9
9
 
10
+ # Initialize fake object
10
11
  def initialize
11
12
  @response = nil
12
13
  end
13
14
 
15
+ # Fake method
14
16
  def connect; end
15
17
 
18
+ # Fake method
16
19
  def detach; end
17
20
 
21
+ # Fake method
18
22
  def detach_for_deleting; end
19
23
 
24
+ # Publish fake message
20
25
  def publish_message(type, _options)
21
26
  @response = Janus::Responses::RSpec.new(type)
22
27
  end
@@ -19,14 +19,18 @@ module RubyRabbitmqJanus
19
19
 
20
20
  # Update attributes to document
21
21
  #
22
- # @param [Hash] List of attribute to update with this value
22
+ # @param attributes [Hash] List of attribute to update with this value
23
+ #
24
+ # @return [Hash] Current model
23
25
  def set(attributes)
24
26
  update_columns(attributes)
25
27
  end
26
28
 
27
29
  # Destroy data to column
28
30
  #
29
- # @param [Array] List to attribute to delete in document
31
+ # @param attributes [Array] List to attribute to delete in document
32
+ #
33
+ # @return [Hash] Current model
30
34
  def unset(attributes)
31
35
  Hash[attributes.map { |key, _value| [key, nil] }]
32
36
  end
@@ -12,8 +12,6 @@ module RubyRabbitmqJanus
12
12
  #
13
13
  # @see file:/config/default.md For more information to config file used.
14
14
  class Event < Concurrency
15
- include Singleton
16
-
17
15
  NAME_VAR = :publish
18
16
 
19
17
  def initialize
@@ -12,8 +12,6 @@ module RubyRabbitmqJanus
12
12
  #
13
13
  # @see file:/config/default.md For more information to config file used.
14
14
  class EventAdmin < Concurrency
15
- include Singleton
16
-
17
15
  NAME_VAR = :publish_adm
18
16
 
19
17
  def initialize
@@ -50,13 +50,6 @@ module RubyRabbitmqJanus
50
50
  rescue => exception
51
51
  raise Errors::Rabbit::Connect::Channel, exception
52
52
  end
53
-
54
- # Create an channel
55
- def channel_pool
56
- @rabbit.create_channel(nil, 8)
57
- rescue => exception
58
- raise Errors::Rabbit::Connect::Channel, exception
59
- end
60
53
  end
61
54
  end
62
55
  end
@@ -12,7 +12,7 @@ module RubyRabbitmqJanus
12
12
  # @param [String] rabbit Information connection to RabbitMQ server
13
13
  def initialize(rabbit)
14
14
  super()
15
- @rabbit = rabbit.channel_pool
15
+ @rabbit = rabbit.channel
16
16
  subscribe_queue
17
17
  rescue
18
18
  raise Errors::Rabbit::Listener::Base::Initialize
@@ -78,4 +78,3 @@ require 'rrj/rabbit/publisher/exclusive'
78
78
  require 'rrj/rabbit/publisher/admin'
79
79
  require 'rrj/rabbit/publisher/keepalive'
80
80
  require 'rrj/rabbit/publisher/non_exclusive'
81
- require 'rrj/rabbit/publisher/janus_instance'
@@ -2,6 +2,7 @@
2
2
 
3
3
  require 'rails'
4
4
  require 'action_view'
5
+ require 'parallel'
5
6
 
6
7
  module RubyRabbitmqJanus
7
8
  # @author VAILLANT Jeremy <jeremy.vaillant@dazzl.tv>
@@ -13,20 +14,23 @@ module RubyRabbitmqJanus
13
14
  class Rails < ::Rails::Engine
14
15
  config.after_initialize do
15
16
  Log.debug '[RRJ] After initializer'
16
- require File.join(Dir.pwd,
17
- RubyRabbitmqJanus::Tools::Config.instance.listener_path)
18
- require File.join(Dir.pwd,
19
- RubyRabbitmqJanus::Tools::Config.instance.listener_admin_path)
17
+ cfg = RubyRabbitmqJanus::Tools::Config.instance
18
+ number = cfg.public_queue_process
20
19
 
21
- process = RubyRabbitmqJanus::Process::Concurrencies
20
+ require File.join(Dir.pwd, cfg.listener_path)
21
+ require File.join(Dir.pwd, cfg.listener_admin_path)
22
22
 
23
- Log.info '[RRJ] Listen public queue in thread'
23
+ Log.debug "[RRJ] Create process : #{number}"
24
+ process = RubyRabbitmqJanus::Process::Concurrencies
24
25
  actions = RubyRabbitmqJanus::ActionEvents.new.actions
25
- process::Event.instance.run(&actions)
26
-
27
- Log.info '[RRJ] Listen admin queue in thread'
28
26
  admin_actions = RubyRabbitmqJanus::ActionAdminEvents.new.actions
29
- process::EventAdmin.instance.run(&admin_actions)
27
+
28
+ Parallel.map([
29
+ process::Event.new.run(&actions),
30
+ process::EventAdmin.new.run(&admin_actions)
31
+ ], in_processes: number) do |listener|
32
+ "Item: #{listener}, Worker: #{Parallel.worker_number}"
33
+ end
30
34
  end
31
35
  end
32
36
  end
@@ -2,4 +2,4 @@
2
2
 
3
3
  require 'rrj/rails'
4
4
 
5
- loop {}
5
+ loop { sleep 1 }
@@ -63,6 +63,11 @@ module RubyRabbitmqJanus
63
63
  @options['gem']['response_path'] || 'spec/responses'
64
64
  end
65
65
 
66
+ # @return [Integer] get number of thread created for listen public queues
67
+ def public_queue_process
68
+ @options['gem']['process'] || 1
69
+ end
70
+
66
71
  alias env environment
67
72
  alias orm object_relational_mapping
68
73
  alias pg program_name
@@ -20,6 +20,7 @@ module RubyRabbitmqJanus
20
20
  # RemoteSyslogger (for papertrail)
21
21
  # File
22
22
  module Logger
23
+ # Write basic information about this gem
23
24
  def self.start
24
25
  Log.info '### Start bin Ruby Rabbit Janus ###'
25
26
  Log.info "Program : #{RubyRabbitmqJanus::Tools::Config.instance.pg}"
@@ -27,6 +28,7 @@ module RubyRabbitmqJanus
27
28
  Log.debug "\r\n#{RubyRabbitmqJanus::BANNER}"
28
29
  end
29
30
 
31
+ # Configure logger used by RRJ
30
32
  def self.create
31
33
  @config = RubyRabbitmqJanus::Tools::Config.instance
32
34
 
@@ -36,6 +38,7 @@ module RubyRabbitmqJanus
36
38
  @log
37
39
  end
38
40
 
41
+ # Choose type logger used in application instance
39
42
  def self.initialize_logger
40
43
  case @config.log_type
41
44
  when :stdout then logger_stdout
@@ -46,14 +49,18 @@ module RubyRabbitmqJanus
46
49
  end
47
50
  end
48
51
 
52
+ # Configure logger with output SDTOUT
49
53
  def self.logger_stdout
50
54
  ::Logger.new(STDOUT)
51
55
  end
52
56
 
57
+ # Configure logger with output file
58
+ # default : `log/ruby-rabbitmq-janus.log`
53
59
  def self.logger_file
54
60
  ::Logger.new(@config.log_option || 'log/ruby-rabbitmq-janus.log')
55
61
  end
56
62
 
63
+ # Configure logger with output PaperTrail service
57
64
  def self.logger_remote
58
65
  require 'remote_syslog_logger'
59
66
 
@@ -63,18 +70,22 @@ module RubyRabbitmqJanus
63
70
  local_hostname: remote_hostname)
64
71
  end
65
72
 
73
+ # Read url for PaperTail and split for endpoint
66
74
  def self.remote_url
67
75
  @config.log_option.split(':').first
68
76
  end
69
77
 
78
+ # Read url for PaperTrail and split for port
70
79
  def self.remote_port
71
80
  @config.log_option.split('@').first.split(':').last
72
81
  end
73
82
 
83
+ # Read url for PaperTrail and split for name app
74
84
  def self.remote_program
75
85
  @config.log_option.split('@').last.split(':').first
76
86
  end
77
87
 
88
+ # Read url for PaperTrail and split for host
78
89
  def self.remote_hostname
79
90
  @config.log_option.split(':').last
80
91
  end
@@ -12,5 +12,5 @@ end
12
12
 
13
13
  # Initialize listener
14
14
  actions = EventTest.new.actions
15
- @event = RubyRabbitmqJanus::Process::Concurrencies::Event.instance
15
+ @event = RubyRabbitmqJanus::Process::Concurrencies::Event.new
16
16
  @event.run(&actions)
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.7.2.pre.320
4
+ version: 2.7.2.pre.322
5
5
  platform: ruby
6
6
  authors:
7
7
  - VAILLANT Jeremy
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-10-18 00:00:00.000000000 Z
11
+ date: 2019-10-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord
@@ -338,6 +338,20 @@ dependencies:
338
338
  - - "~>"
339
339
  - !ruby/object:Gem::Version
340
340
  version: '1.2'
341
+ - !ruby/object:Gem::Dependency
342
+ name: parallel
343
+ requirement: !ruby/object:Gem::Requirement
344
+ requirements:
345
+ - - "~>"
346
+ - !ruby/object:Gem::Version
347
+ version: '1.18'
348
+ type: :runtime
349
+ prerelease: false
350
+ version_requirements: !ruby/object:Gem::Requirement
351
+ requirements:
352
+ - - "~>"
353
+ - !ruby/object:Gem::Version
354
+ version: '1.18'
341
355
  - !ruby/object:Gem::Dependency
342
356
  name: semaphore
343
357
  requirement: !ruby/object:Gem::Requirement
@@ -454,12 +468,10 @@ files:
454
468
  - lib/rrj/errors/rabbit/listener/base.rb
455
469
  - lib/rrj/errors/rabbit/listener/from.rb
456
470
  - lib/rrj/errors/rabbit/listener/from_admin.rb
457
- - lib/rrj/errors/rabbit/listener/janus_instance.rb
458
471
  - lib/rrj/errors/rabbit/propertie.rb
459
472
  - lib/rrj/errors/rabbit/publisher/admin.rb
460
473
  - lib/rrj/errors/rabbit/publisher/base.rb
461
474
  - lib/rrj/errors/rabbit/publisher/exclusive.rb
462
- - lib/rrj/errors/rabbit/publisher/janus_instance.rb
463
475
  - lib/rrj/errors/rabbit/publisher/keepalive.rb
464
476
  - lib/rrj/errors/rabbit/publisher/non_exclusive.rb
465
477
  - lib/rrj/errors/rabbit/rabbit.rb
@@ -479,7 +491,6 @@ files:
479
491
  - lib/rrj/janus/messages/standard.rb
480
492
  - lib/rrj/janus/responses/admin.rb
481
493
  - lib/rrj/janus/responses/event.rb
482
- - lib/rrj/janus/responses/janus_instance.rb
483
494
  - lib/rrj/janus/responses/response.rb
484
495
  - lib/rrj/janus/responses/rspec.rb
485
496
  - lib/rrj/janus/responses/standard.rb
@@ -504,7 +515,6 @@ files:
504
515
  - lib/rrj/rabbit/publisher/admin.rb
505
516
  - lib/rrj/rabbit/publisher/base.rb
506
517
  - lib/rrj/rabbit/publisher/exclusive.rb
507
- - lib/rrj/rabbit/publisher/janus_instance.rb
508
518
  - lib/rrj/rabbit/publisher/keepalive.rb
509
519
  - lib/rrj/rabbit/publisher/non_exclusive.rb
510
520
  - lib/rrj/rabbit/rabbit.rb
@@ -1,18 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module RubyRabbitmqJanus
4
- module Errors
5
- module Rabbit
6
- module Listener
7
- module JanusInstance
8
- # Error class for listenern janusInstance
9
- class ListenEvents < RubyRabbitmqJanus::Errors::Rabbit::Listener::BaseError
10
- def initialize(error)
11
- super "Error for listen events in RabbitMQ public queue, #{error}"
12
- end
13
- end
14
- end
15
- end
16
- end
17
- end
18
- end
@@ -1,25 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- # :reek:IrresponsibleModule
4
-
5
- module RubyRabbitmqJanus
6
- module Errors
7
- module Rabbit
8
- module Publisher
9
- module JanusInstance
10
- class Initialize < RubyRabbitmqJanus::Errors::Rabbit::Publisher::BasePublishExclusive
11
- def initialize
12
- super 'Error in initializer'
13
- end
14
- end
15
-
16
- class Publish < RubyRabbitmqJanus::Errors::Rabbit::Publisher::BasePublisherAdmin
17
- def initialize
18
- super 'Error publish message in queue'
19
- end
20
- end
21
- end
22
- end
23
- end
24
- end
25
- end
@@ -1,28 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'rrj/janus/responses/response'
4
-
5
- module RubyRabbitmqJanus
6
- module Janus
7
- module Responses
8
- # Janus Instanece response.
9
- class JanusInstance < Response
10
- def event
11
- 'JanusInstance update'
12
- end
13
-
14
- def id
15
- request['id']
16
- end
17
-
18
- def instance
19
- JanusInstance.find(id)
20
- end
21
-
22
- def enable
23
- request['enable']
24
- end
25
- end
26
- end
27
- end
28
- end
@@ -1,27 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module RubyRabbitmqJanus
4
- module Rabbit
5
- module Publisher
6
- # Publisher to queue `janus-instance`
7
- class JanusInstance
8
- def initialize
9
- @rabbit = RubyRabbitmqJanus::Rabbit::Connect.new
10
- rescue
11
- raise Errors::Rabbit::Publisher::JanusInstance::Initialize
12
- end
13
-
14
- def publish(data)
15
- @rabbit.start
16
- channel = @rabbit.channel
17
- queue = channel.queue(Tools::Config.instance.queue_janus_instance)
18
- channel.default_exchange.publish(data.to_json,
19
- routing_key: queue.name)
20
- @rabbit.close
21
- rescue
22
- raise Errors::Rabbit::Publisher::JanusInstance::Publish
23
- end
24
- end
25
- end
26
- end
27
- end