asynchronic 3.0.0 → 3.0.1

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
  SHA1:
3
- metadata.gz: fe064d93526974fae713afcd2d5fc4730cb65b94
4
- data.tar.gz: f6ca2831a8d78323370116397d1cbb9d48c66837
3
+ metadata.gz: 0e0f25f70fa41da06affe41aa2fb639b7bfd542a
4
+ data.tar.gz: 0a59f33dece383cd47df04ee457221101bbed618
5
5
  SHA512:
6
- metadata.gz: a6668033166027a2d54aca7b094f8f90642f4b180f01299e99099a62b47f3dffd871799773248c3ad0bb3a4127885029234cda953265782926b685a5596743b3
7
- data.tar.gz: 86da5ba9d7207fae1d6f01f77f433f8ed7e3b6d6e64e3bec177755088ee0c844f5c8a768f942c905ce730d9ea1d6dfcf5caee4db1a83b20bbf4a7727a721ed04
6
+ metadata.gz: 80d20d5b4ca50a04ed124b03d7b76000847a433877b45bb7bd2dc77e22f0984ec6f4215af76bd5a881a5bd550b67725a3a1d856698f96d878f9f55725e181c67
7
+ data.tar.gz: 51c7ed3e8686731277c31fbdea1bcb2bfc62c10959fbbcab7cf46a4d0cf6dc7f7ff2c6063eb5eea4809aeed773a150593787b1fdef6ca1d7afef8cf2c4531ed1
data/lib/asynchronic.rb CHANGED
@@ -24,8 +24,8 @@ module Asynchronic
24
24
  attr_config :retry_timeout, 30
25
25
  attr_config :garbage_collector_timeout, 30
26
26
  attr_config :redis_data_store_sync_timeout, 0.01
27
- attr_config :keep_alive_timeout, 0.1
28
- attr_config :connection_name, "HOST=#{Socket.gethostname},PID=#{::Process.pid}"
27
+ attr_config :keep_alive_timeout, 1
28
+ attr_config :connection_name, "HOST=#{Socket.gethostname},PID=#{::Process.pid},UUID=#{SecureRandom.uuid}"
29
29
 
30
30
  def self.environment
31
31
  Environment.new queue_engine, data_store, notifier
@@ -12,7 +12,7 @@ module Asynchronic
12
12
  end
13
13
 
14
14
  def [](key)
15
- value = @redis.call 'GET', @scope[key]
15
+ value = @redis.call! 'GET', @scope[key]
16
16
  value ? Marshal.load(value) : nil
17
17
  rescue => ex
18
18
  Asynchronic.logger.warn('Asynchronic') { ex.message }
@@ -20,29 +20,29 @@ module Asynchronic
20
20
  end
21
21
 
22
22
  def []=(key, value)
23
- @redis.call 'SET', @scope[key], Marshal.dump(value)
23
+ @redis.call! 'SET', @scope[key], Marshal.dump(value)
24
24
  end
25
25
 
26
26
  def delete(key)
27
- @redis.call 'DEL', @scope[key]
27
+ @redis.call! 'DEL', @scope[key]
28
28
  end
29
29
 
30
30
  def delete_cascade(key)
31
- @redis.call 'DEL', @scope[key]
32
- @redis.call('KEYS', @scope[key]['*']).each { |k| @redis.call 'DEL', k }
31
+ @redis.call! 'DEL', @scope[key]
32
+ @redis.call!('KEYS', @scope[key]['*']).each { |k| @redis.call! 'DEL', k }
33
33
  end
34
34
 
35
35
  def keys
36
- @redis.call('KEYS', @scope['*']).map { |k| Key[k].remove_first }
36
+ @redis.call!('KEYS', @scope['*']).map { |k| Key[k].remove_first }
37
37
  end
38
38
 
39
39
  def synchronize(key)
40
- while @redis.call('GETSET', @scope[key][LOCKED], LOCKED) == LOCKED
40
+ while @redis.call!('GETSET', @scope[key][LOCKED], LOCKED) == LOCKED
41
41
  sleep Asynchronic.redis_data_store_sync_timeout
42
42
  end
43
43
  yield
44
44
  ensure
45
- @redis.call 'DEL', @scope[key][LOCKED]
45
+ @redis.call! 'DEL', @scope[key][LOCKED]
46
46
  end
47
47
 
48
48
  def connection_args
@@ -267,6 +267,9 @@ module Asynchronic
267
267
 
268
268
  def connected?
269
269
  connection_name && environment.queue_engine.active_connections.include?(connection_name)
270
+ rescue => ex
271
+ Asynchronic.logger.error('Asynchronic') { "#{ex.message}\n#{ex.backtrace.join("\n")}" }
272
+ true
270
273
  end
271
274
 
272
275
  end
@@ -16,12 +16,12 @@ module Asynchronic
16
16
  end
17
17
 
18
18
  def queues
19
- (@queues.values.map(&:key) | redis.call('KEYS', 'ost:*')).map { |q| q.to_s[4..-1].to_sym }
19
+ (@queues.values.map(&:key) | redis.call!('KEYS', 'ost:*')).map { |q| q.to_s[4..-1].to_sym }
20
20
  end
21
21
 
22
22
  def clear
23
23
  @queues.clear
24
- redis.call('KEYS', 'ost:*').each { |k| redis.call('DEL', k) }
24
+ redis.call!('KEYS', 'ost:*').each { |k| redis.call!('DEL', k) }
25
25
  end
26
26
 
27
27
  def listener
@@ -33,9 +33,10 @@ module Asynchronic
33
33
  end
34
34
 
35
35
  def active_connections
36
- redis.call('CLIENT', 'LIST').split("\n").map do |connection_info|
37
- connection_info.split(' ').detect { |a| a.match(/name=/) }[5..-1]
38
- end.uniq.reject(&:empty?)
36
+ redis.call!('CLIENT', 'LIST').split("\n").map do |connection_info|
37
+ name_attr = connection_info.split(' ').detect { |a| a.match(/name=/) }
38
+ name_attr ? name_attr[5..-1] : nil
39
+ end.uniq.compact.reject(&:empty?)
39
40
  end
40
41
 
41
42
  private
@@ -43,7 +44,7 @@ module Asynchronic
43
44
  def notify_keep_alive
44
45
  Thread.new do
45
46
  loop do
46
- redis.call 'CLIENT', 'SETNAME', Asynchronic.connection_name
47
+ redis.call! 'CLIENT', 'SETNAME', Asynchronic.connection_name
47
48
  sleep Asynchronic.keep_alive_timeout
48
49
  end
49
50
  end
@@ -58,11 +59,11 @@ module Asynchronic
58
59
  end
59
60
 
60
61
  def pop
61
- redis.call 'RPOP', key
62
+ redis.call! 'RPOP', key
62
63
  end
63
64
 
64
65
  def empty?
65
- redis.call('EXISTS', key) == 0
66
+ redis.call!('EXISTS', key) == 0
66
67
  end
67
68
 
68
69
  def size
@@ -1,3 +1,3 @@
1
1
  module Asynchronic
2
- VERSION = '3.0.0'
2
+ VERSION = '3.0.1'
3
3
  end
data/spec/facade_spec.rb CHANGED
@@ -69,11 +69,11 @@ describe Asynchronic, 'Facade' do
69
69
  end
70
70
 
71
71
  it 'Keep alive timeout' do
72
- Asynchronic.keep_alive_timeout.must_equal 0.1
72
+ Asynchronic.keep_alive_timeout.must_equal 1
73
73
  end
74
74
 
75
75
  it 'Connection name' do
76
- Asynchronic.connection_name.must_equal "HOST=#{Socket.gethostname},PID=#{::Process.pid}"
76
+ Asynchronic.connection_name.must_match /^HOST=#{Socket.gethostname},PID=#{::Process.pid}/
77
77
  end
78
78
 
79
79
  end
data/spec/jobs.rb CHANGED
@@ -200,7 +200,7 @@ end
200
200
  class WithRetriesJob < Asynchronic::Job
201
201
  def call
202
202
  @counter = 0
203
- retry_when [RuntimeError] do
203
+ retry_when [RuntimeError], 0.1 do
204
204
  @counter += 1
205
205
  raise 'Counter < 3' if @counter < 3
206
206
  @counter
@@ -29,8 +29,13 @@ module LifeCycleExamples
29
29
 
30
30
  process.must_have_connection_name
31
31
  process.wont_be :dead?
32
+
32
33
  process.send(:connected?).must_be_true
33
34
 
35
+ env.queue_engine.stub(:active_connections, ->() { raise 'Forced error' }) do
36
+ process.send(:connected?).must_be_true
37
+ end
38
+
34
39
  with_retries do
35
40
  events.last.must_equal process.status
36
41
  process.finalized?.must_equal is_finalized
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: asynchronic
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.0.0
4
+ version: 3.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Gabriel Naiman
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-06-24 00:00:00.000000000 Z
11
+ date: 2019-07-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: ost