ruby_rabbitmq_janus 2.2.2 → 2.3.0.pre.170

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: 358887b9e59758b7950a69d1ae571a266c5f5bf3f4eef0191a12594e34570362
4
- data.tar.gz: ba781a23afa2913cbe4324f6410459beae49c66ceb615375349ed83d17282d49
3
+ metadata.gz: 2199de64c8b40d5f83cc1359124c2a723eb77c527396bd5a64a4272938a96f4c
4
+ data.tar.gz: b6d0de19bbcef76110c3ad405174bae6120c43d50eb7865baa65f5956511f498
5
5
  SHA512:
6
- metadata.gz: 35187cc5f01a6251aee1dbfe9996a4dae24c825def8f9844ef134f72eea5a81c80cd4e2c27a3d172dea19d1748936155281da00af64e706fdbc4d66c642c08c6
7
- data.tar.gz: ddaa4e423cf02e148629fdaad043171e472e4c304e12a0ef0c639208ab10a552fa79f78a40d88ed7fb97fa22059b6b3f33160ac4c7ebccd912bdf7a2d29dbbf9
6
+ metadata.gz: a652690ada2cda692dbb908d14983f490e423eee4c085aa5ccf65cc86e048392b99fcb8871428dbae7d80e3e3b4caaf17c0c89a3b4d00f4b216629b3f9f9eb37
7
+ data.tar.gz: ef190a5aed5e25dcc3e43516f5d499945e7f6ae9fc99e063a60af189ac69967fbf145bed5f29dad9083905279ced3236c6be3c8d63357b4426e5afb1fdaf64a4
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.2.2'
9
+ VERSION = '2.3.0'
10
10
 
11
11
  # Name to gem
12
12
  GEM_NAME = 'ruby_rabbitmq_janus'
@@ -13,7 +13,7 @@ module RubyRabbitmqJanus
13
13
  attr_reader :instance
14
14
 
15
15
  def initialize(instance)
16
- @instance = instance
16
+ @instance = instance.id
17
17
  end
18
18
 
19
19
  def session
@@ -17,6 +17,8 @@ module RubyRabbitmqJanus
17
17
  @rabbit = rabbit
18
18
  @timer = KeepaliveTimer.new
19
19
  @message = KeepaliveMessage.new(instance)
20
+ instance.set(thread: __id__)
21
+ Tools::Log.instance.info "Keepalive thread id is #{__id__}"
20
22
  super(&block)
21
23
  rescue
22
24
  raise Errors::Janus::KeepaliveThread::Initializer
@@ -35,8 +37,12 @@ module RubyRabbitmqJanus
35
37
  def restart_session
36
38
  Tools::Log.instance.warn 'Restart session ...'
37
39
  janus = find_model
38
- send_messages_restart
39
- janus.set(session: @session)
40
+ if janus.present?
41
+ send_messages_restart
42
+ janus.set(session: @session)
43
+ else
44
+ Tools::Log.instance.error 'Janus Instance Model is gone, giving up'
45
+ end
40
46
  rescue
41
47
  raise Errors::Janus::KeepaliveThread::RestartSession
42
48
  end
@@ -44,9 +50,18 @@ module RubyRabbitmqJanus
44
50
  # Start a timer for TTL
45
51
  def start
46
52
  @timer.loop_keepalive do
47
- Tools::Log.instance.info 'Send keepalive to instance ' \
48
- "#{@message.instance} with TTL #{@timer.time_to_live}"
49
- response_keepalive
53
+ if detached?(find_model)
54
+ Tools::Log.instance.info \
55
+ "Thread #{__id__} no longer attached to Janus Instance, exiting..."
56
+ @timer.stop_timer
57
+ cleanup
58
+ exit
59
+ else
60
+ Tools::Log.instance.info "Thread #{__id__} " \
61
+ 'sending keepalive to instance ' \
62
+ "#{@message.instance} with TTL #{@timer.time_to_live}"
63
+ response_keepalive
64
+ end
50
65
  end
51
66
  rescue
52
67
  raise Errors::Janus::KeepaliveThread::Start
@@ -54,10 +69,7 @@ module RubyRabbitmqJanus
54
69
 
55
70
  # Kill session and disable instance
56
71
  def kill
57
- if @session.present? && @message.present?
58
- response_destroy if find_model.enable
59
- end
60
- @rabbit.close
72
+ cleanup
61
73
  super
62
74
  rescue
63
75
  raise Errors::Janus::KeepaliveThread::Kill
@@ -65,10 +77,15 @@ module RubyRabbitmqJanus
65
77
 
66
78
  def instance_is_down
67
79
  janus = find_model
68
- janus.set(enable: false).unset(%I[thread session])
69
- Tools::Log.instance.fatal \
70
- "Janus Instance [#{janus.instance}] is down, kill thread."
71
- prepare_kill_thread
80
+ @session = @message = nil
81
+ if detached?(janus)
82
+ Tools::Log.instance.error\
83
+ "Thread [#{__id__}] no longer attached to Janus Instance (should be dead)."
84
+ else
85
+ janus.set(enable: false).unset(%I[thread session])
86
+ Tools::Log.instance.fatal \
87
+ "Janus Instance [#{janus.instance}] is down, thread [#{__id__}] will die."
88
+ end
72
89
  rescue
73
90
  raise Errors::Janus::KeepaliveThread::InstanceIsDown
74
91
  end
@@ -82,17 +99,26 @@ module RubyRabbitmqJanus
82
99
  response_keepalive
83
100
  end
84
101
 
85
- def prepare_kill_thread
86
- @session = @message = nil
87
- KeepaliveThread.instance_method(:kill).bind(self).call
102
+ def cleanup
103
+ if @session.present? && @message.present?
104
+ response_destroy
105
+ end
106
+ @rabbit.close
88
107
  end
89
108
 
90
109
  def find_model
91
- if @session.blank?
110
+ if (@message.present?)
92
111
  Models::JanusInstance.find(@message.instance)
93
112
  else
113
+ Tools::Log.instance.warn 'Lookup Janus Instance model by session [#{@session}]'
94
114
  Models::JanusInstance.find_by_session(@session)
95
115
  end
116
+ rescue
117
+ nil
118
+ end
119
+
120
+ def detached?(janus)
121
+ janus.blank? or janus.thread != __id__
96
122
  end
97
123
 
98
124
  def publisher
@@ -25,7 +25,7 @@ module RubyRabbitmqJanus
25
25
  def initialize
26
26
  @time_to_live = Tools::Config.instance.ttl
27
27
  @time_to_die = test_time_to_die >= 60 ? 59 : test_time_to_die
28
- @timer = Timers::Group.new
28
+ @timers = Timers::Group.new
29
29
  rescue
30
30
  raise Errors::Janus::KeepaliveTimer::Initializer
31
31
  end
@@ -33,8 +33,8 @@ module RubyRabbitmqJanus
33
33
  # Execute a loop with timer for sending keepalive message
34
34
  # to Janus Instance
35
35
  def loop_keepalive(&block)
36
- @timer.now_and_every(@time_to_live) { prepare_loop(&block) }
37
- loop { @timer.wait }
36
+ @timer = @timers.now_and_every(@time_to_live) { prepare_loop(&block) }
37
+ loop { @timers.wait }
38
38
  rescue
39
39
  raise Errors::Janus::KeepaliveTimer::LoopKeepalive
40
40
  end
@@ -43,7 +43,6 @@ module RubyRabbitmqJanus
43
43
  def session(&block)
44
44
  Timeout.timeout(@time_to_die) { yield }
45
45
  rescue Timeout::Error
46
- stop_timer
47
46
  block.binding.receiver.instance_is_down
48
47
  rescue
49
48
  raise Errors::Janus::KeepaliveTimer::Session
@@ -51,18 +50,11 @@ module RubyRabbitmqJanus
51
50
 
52
51
  # Stop timer to keepalive thread
53
52
  def stop_timer
54
- @timer.pause
53
+ @timer.cancel
55
54
  rescue
56
55
  raise Errors::Janus::KeepaliveTimer::StopTimer
57
56
  end
58
57
 
59
- # Start timer to keepalive thread
60
- def start_timer
61
- @timer.resume
62
- rescue
63
- raise Errors::Janus::KeepaliveTimer::StartTimer
64
- end
65
-
66
58
  private
67
59
 
68
60
  def prepare_loop(&block)
@@ -70,7 +62,6 @@ module RubyRabbitmqJanus
70
62
  block.binding.receiver.restart_session if yield
71
63
  end
72
64
  rescue Timeout::Error
73
- stop_timer
74
65
  block.binding.receiver.instance_is_down
75
66
  end
76
67
 
@@ -27,7 +27,7 @@ module RubyRabbitmqJanus
27
27
  # Destroy a session in Janus Instance
28
28
  def callback_destroy_after
29
29
  Tools::Log.instance.debug 'Callback AFTER_DESTROY'
30
- destroy_a_session_in_janus_instance if enable && session? && thread?
30
+ #LCO: nothing to do, thread will close session and die
31
31
  end
32
32
 
33
33
  private
@@ -35,13 +35,11 @@ module RubyRabbitmqJanus
35
35
  def create_a_session_in_janus_instance
36
36
  info_instance('Create session')
37
37
  janus_instance = keepalive_object_new
38
- set(session: janus_instance.session, thread: janus_instance.thread_id)
38
+ set(session: janus_instance.session)
39
39
  end
40
40
 
41
41
  def destroy_a_session_in_janus_instance
42
- info_instance('Destroy session')
43
- keepalive_object_thread.send(:response_destroy)
44
- keepalive_object_thread.kill
42
+ info_instance('Detaching session')
45
43
  unset(%I[thread session])
46
44
  end
47
45
 
@@ -50,7 +48,7 @@ module RubyRabbitmqJanus
50
48
  end
51
49
 
52
50
  def keepalive_object_new
53
- keepalive_object.new(instance)
51
+ keepalive_object.new(self)
54
52
  end
55
53
 
56
54
  def keepalive_object_thread
data/spec/spec_helper.rb CHANGED
@@ -59,7 +59,7 @@ RSpec.configure do |config|
59
59
 
60
60
  # Configure Initializer RRJ and create session with Janus Instance
61
61
  config.before(:example) do |example|
62
- unless example.metadata[:type].match?(/thread/) || example.metadata[:type].match?(/tools/)
62
+ unless example.metadata[:type].match?(/tools/)
63
63
  after_load_database
64
64
  initializer_rrj(example.metadata)
65
65
  clear
@@ -3,9 +3,8 @@
3
3
  require 'spec_helper'
4
4
 
5
5
  describe RubyRabbitmqJanus::Janus::Concurrencies::KeepaliveThread, type: :thread, name: :keepalive_initializer do
6
- let(:instance) { [1, 2].sample }
6
+ let(:instance) { RubyRabbitmqJanus::Models::JanusInstance.find((ENV['MONGO'].match?('true')? ['1','2']:[1,2]).sample) }
7
7
  let(:concurrency) { RubyRabbitmqJanus::Janus::Concurrencies::KeepaliveInitializer.new(instance) }
8
-
9
8
  it { expect(concurrency.send(:rabbit)).to be_a(RubyRabbitmqJanus::Rabbit::Connect) }
10
9
  it { expect(concurrency.send(:lock)).to be_a(Mutex) }
11
10
  it { expect(concurrency.send(:condition)).to be_a(ConditionVariable) }
@@ -3,7 +3,7 @@
3
3
  require 'spec_helper'
4
4
 
5
5
  describe RubyRabbitmqJanus::Janus::Concurrencies::KeepaliveThread, type: :thread, name: :keepalive_thread do
6
- let(:instance) { [1, 2].sample }
6
+ let(:instance) { RubyRabbitmqJanus::Models::JanusInstance.find((ENV['MONGO'].match?('true')? ['1','2']:[1,2]).sample) }
7
7
  let(:rabbit) { RubyRabbitmqJanus::Janus::Concurrencies::Concurrency.new.send(:rabbit) }
8
8
  let(:concurrency) { RubyRabbitmqJanus::Janus::Concurrencies::KeepaliveThread.new(instance, rabbit) { nil } }
9
9
 
@@ -7,6 +7,6 @@ describe RubyRabbitmqJanus::Janus::Concurrencies::KeepaliveTimer, type: :thread,
7
7
 
8
8
  it { expect(concurrency.send(:time_to_live)).to be_a(Integer) }
9
9
  it { expect(concurrency.send(:time_to_die)).to be_a(Integer) }
10
- it { expect(concurrency.instance_variable_get(:@timer)).to be_a(Timers::Group) }
10
+ it { expect(concurrency.instance_variable_get(:@timers)).to be_a(Timers::Group) }
11
11
  it { expect(concurrency.instance_variable_get(:@time_to_live)).to eql(RubyRabbitmqJanus::Tools::Config.instance.options['janus']['session']['keepalive']) }
12
12
  end
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.2.2
4
+ version: 2.3.0.pre.170
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-12-21 00:00:00.000000000 Z
11
+ date: 2018-01-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -612,9 +612,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
612
612
  version: '0'
613
613
  required_rubygems_version: !ruby/object:Gem::Requirement
614
614
  requirements:
615
- - - ">="
615
+ - - ">"
616
616
  - !ruby/object:Gem::Version
617
- version: '0'
617
+ version: 1.3.1
618
618
  requirements: []
619
619
  rubyforge_project:
620
620
  rubygems_version: 2.7.2