ruby_rabbitmq_janus 3.0.0.pre.352 → 3.0.0.pre.354

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 9410fdf3db086fdaf0c7abd7c822612977718f0d2059869ec0bfd5522e30dacf
4
- data.tar.gz: dfe4addba32bc68b336cb4db8177a791589cde45ed73d78799fc7d298ef129a0
3
+ metadata.gz: c734f054b82c7313cc2f700856897005589fc8cd85083b21562ee2574ad038eb
4
+ data.tar.gz: 617e6caa75c5cad2280d07c6056161a25ed549d825fb9524ae6cc3c098132085
5
5
  SHA512:
6
- metadata.gz: 99ea49a811322ecc33e84b2f7fc03bc181b9b515520debbceaf922b59fc0007073ae571f4fb1e9004052c04596606efabacbfdda8a7157bbf411d8ca8f1b7900
7
- data.tar.gz: 2ca3d7bc242cb865bc397f21d43be8504af0b2e40cb9c77907f4120867a2b10adc8fa9ada6d3b5714b9f4c33d41d871d1bc12cb9a92010731a9dbd47909b0c2b
6
+ metadata.gz: 9ec5a373c987a2bf9c18d2ea1b1478a6a4814967af89d73cdc7a04cd0cd79922d8f9e7ad6d5d4da555e64f1f23c13598da1ba403d7f84741da424154e92ff22a
7
+ data.tar.gz: 74ab344770f32f388f0fcb009dd90e82388b74b1dd8732903ef6c658a0b714b084f7595bee353419510ef08f65f2fc41499e09a2a12c1ef6f050802bf2d28918
@@ -22,22 +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 \
31
+ "Close a connection with RabbitMQ instance for #{self.class.name}"
29
32
  @rabbit.close
30
33
  end
31
34
 
32
35
  def info_thread
33
36
  "Create an thread -- #{self.class.name}"
34
37
  end
35
-
36
- attr_reader :lock, :condition, :rabbit
37
38
  end
38
39
  end
39
40
  end
40
41
  end
41
42
 
43
+ require 'rrj/process/thread_runner_concern'
42
44
  require 'rrj/process/event'
43
45
  require 'rrj/process/event_admin'
@@ -12,41 +12,21 @@ module RubyRabbitmqJanus
12
12
  #
13
13
  # @see file:/config/default.md For more information to config file used.
14
14
  class Event < Concurrency
15
- NAME_VAR = :publish
15
+ include RubyRabbitmqJanus::Process::Concurrencies::ThreadRunnerConcern
16
16
 
17
- def initialize
18
- super
19
- @thread = Thread.new { initialize_thread }
20
- end
21
-
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?
17
+ private
32
18
 
33
- @thread.join
34
- Thread.new do
35
- loop do
36
- @thread.thread_variable_get(NAME_VAR).listen_events(&block)
37
- end
38
- end
19
+ def raise_nil_block
20
+ raise RubyRabbitmqJanus::Errors::Process::Event::Run
39
21
  end
40
22
 
41
- private
23
+ def name_publisher
24
+ :publish
25
+ end
42
26
 
43
27
  def publisher
44
28
  Rabbit::Listener::From.new(rabbit)
45
29
  end
46
-
47
- def transaction_running
48
- @thread.thread_variable_set(NAME_VAR, publisher)
49
- end
50
30
  end
51
31
  end
52
32
  end
@@ -12,41 +12,21 @@ module RubyRabbitmqJanus
12
12
  #
13
13
  # @see file:/config/default.md For more information to config file used.
14
14
  class EventAdmin < Concurrency
15
- NAME_VAR = :publish_adm
15
+ include RubyRabbitmqJanus::Process::Concurrencies::ThreadRunnerConcern
16
16
 
17
- def initialize
18
- super
19
- @thread = Thread.new { initialize_thread }
20
- end
21
-
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?
17
+ private
32
18
 
33
- @thread.join
34
- Thread.new do
35
- loop do
36
- @thread.thread_variable_get(NAME_VAR).listen_events(&block)
37
- end
38
- end
19
+ def raise_nil_block
20
+ raise RubyRabbitmqJanus::Errors::Process::EventAdmin::Run
39
21
  end
40
22
 
41
- private
23
+ def name_publisher
24
+ :publish_adm
25
+ end
42
26
 
43
27
  def publisher
44
28
  Rabbit::Listener::FromAdmin.new(rabbit)
45
29
  end
46
-
47
- def transaction_running
48
- @thread.thread_variable_set(NAME_VAR, publisher)
49
- end
50
30
  end
51
31
  end
52
32
  end
@@ -0,0 +1,55 @@
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
+ # Initialize an process (event/event_admin) and configure
17
+ # the life cycle to thread.
18
+ def initialize
19
+ super
20
+ @thread = Thread.new { initialize_thread }
21
+ @thread.abort_on_exception = true
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_given?
35
+
36
+ @thread.join
37
+ Thread.new do
38
+ loop do
39
+ @thread.thread_variable_get(name_publisher).listen_events(&block)
40
+ rescue => exception
41
+ ::Log.warn 'An exception to was encountered in the thread !'
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
@@ -6,8 +6,8 @@ shared_examples 'when thread' do
6
6
  let(:action) { EventTest.new.actions }
7
7
  let(:size) { (rand * 10).to_i }
8
8
 
9
- it { expect(concurrency::NAME_VAR).to be_a(Symbol) }
10
- it { expect(concurrency::NAME_VAR).to eql(publish_name) }
9
+ it { expect(event.send(:name_publisher)).to be_a(Symbol) }
10
+ it { expect(event.send(:name_publisher)).to eql(publish_name) }
11
11
  it { expect(action).not_to be(nil) }
12
12
  it { expect { event.run(&action) }.not_to raise_error(exception_runner) }
13
13
  it { expect { event.run }.to raise_error(exception_runner) }
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: 3.0.0.pre.352
4
+ version: 3.0.0.pre.354
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-12-19 00:00:00.000000000 Z
11
+ date: 2019-12-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord
@@ -513,6 +513,7 @@ files:
513
513
  - lib/rrj/process/concurrency.rb
514
514
  - lib/rrj/process/event.rb
515
515
  - lib/rrj/process/event_admin.rb
516
+ - lib/rrj/process/thread_runner_concern.rb
516
517
  - lib/rrj/rabbit/base_event.rb
517
518
  - lib/rrj/rabbit/connect.rb
518
519
  - lib/rrj/rabbit/listener/base.rb