asynchronic 1.6.3 → 2.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +0 -2
- data/asynchronic.gemspec +1 -8
- data/lib/asynchronic.rb +5 -1
- data/lib/asynchronic/data_store/lazy_value.rb +1 -1
- data/lib/asynchronic/data_store/redis.rb +10 -10
- data/lib/asynchronic/process.rb +13 -2
- data/lib/asynchronic/queue_engine/in_memory.rb +5 -0
- data/lib/asynchronic/queue_engine/ost.rb +22 -14
- data/lib/asynchronic/queue_engine/synchronic.rb +5 -0
- data/lib/asynchronic/version.rb +2 -2
- data/lib/asynchronic/worker.rb +1 -1
- data/spec/data_store/data_store_examples.rb +10 -10
- data/spec/expectations.rb +6 -1
- data/spec/facade_spec.rb +12 -0
- data/spec/minitest_helper.rb +1 -0
- data/spec/process/life_cycle_examples.rb +12 -21
- data/spec/queue_engine/queue_engine_examples.rb +13 -7
- data/spec/queue_engine/synchronic_spec.rb +5 -1
- metadata +4 -18
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7a0200ef4e9c9c465ddc70786d71e15bb2fa2f4d
|
4
|
+
data.tar.gz: 0d5320739a21a0cd57f7e65cfe28d6dea571dbfb
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2294c1215c7b3abb787c3ec9cd955b254b9b1ec235e6c028d1ff9620b881bc0f0a7ed937b98b14e1ef2537b0be2921e67772ccaec1d9b37616bccc8a11fbe8cf
|
7
|
+
data.tar.gz: 8fa59d9eeafa9a952a9c76c2b91c807d4eaa0fcbc58ee2b1bed1bd637358b42f4c2ef8e1fb1bb864bad86664e45c67fbc44e8bd8e2099dedda6b6e08e95e6cc2
|
data/.travis.yml
CHANGED
data/asynchronic.gemspec
CHANGED
@@ -18,8 +18,7 @@ Gem::Specification.new do |spec|
|
|
18
18
|
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
19
|
spec.require_paths = ['lib']
|
20
20
|
|
21
|
-
spec.add_dependency '
|
22
|
-
spec.add_dependency 'ost', '~> 0.1'
|
21
|
+
spec.add_dependency 'ost', '~> 1.0'
|
23
22
|
spec.add_dependency 'class_config', '~> 0.0'
|
24
23
|
spec.add_dependency 'transparent_proxy', '~> 0.0'
|
25
24
|
spec.add_dependency 'multi_require', '~> 1.0'
|
@@ -33,10 +32,4 @@ Gem::Specification.new do |spec|
|
|
33
32
|
spec.add_development_dependency 'simplecov', '~> 0.12'
|
34
33
|
spec.add_development_dependency 'coveralls', '~> 0.8'
|
35
34
|
spec.add_development_dependency 'pry-nav', '~> 0.2'
|
36
|
-
|
37
|
-
if RUBY_VERSION < '2'
|
38
|
-
spec.add_development_dependency 'term-ansicolor', '~> 1.3.0'
|
39
|
-
spec.add_development_dependency 'tins', '~> 1.6.0'
|
40
|
-
spec.add_development_dependency 'json', '~> 1.8'
|
41
|
-
end
|
42
35
|
end
|
data/lib/asynchronic.rb
CHANGED
@@ -1,11 +1,13 @@
|
|
1
1
|
require 'forwardable'
|
2
2
|
require 'securerandom'
|
3
|
-
require 'redis'
|
4
3
|
require 'ost'
|
4
|
+
require 'redic'
|
5
5
|
require 'class_config'
|
6
6
|
require 'transparent_proxy'
|
7
7
|
require 'logger'
|
8
8
|
require 'multi_require'
|
9
|
+
require 'timeout'
|
10
|
+
require 'socket'
|
9
11
|
|
10
12
|
MultiRequire.require_relative_pattern 'asynchronic/**/*.rb'
|
11
13
|
|
@@ -20,6 +22,8 @@ module Asynchronic
|
|
20
22
|
attr_config :retry_timeout, 30
|
21
23
|
attr_config :garbage_collector_timeout, 30
|
22
24
|
attr_config :redis_data_store_sync_timeout, 0.01
|
25
|
+
attr_config :keep_alive_timeout, 0.1
|
26
|
+
attr_config :connection_name, "HOST=#{Socket.gethostname},PID=#{::Process.pid}"
|
23
27
|
|
24
28
|
def self.environment
|
25
29
|
Environment.new queue_engine, data_store
|
@@ -8,11 +8,11 @@ module Asynchronic
|
|
8
8
|
|
9
9
|
def initialize(scope, *args)
|
10
10
|
@scope = Key[scope]
|
11
|
-
@
|
11
|
+
@redis = Redic.new(*args)
|
12
12
|
end
|
13
13
|
|
14
14
|
def [](key)
|
15
|
-
value = @
|
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,33 +20,33 @@ module Asynchronic
|
|
20
20
|
end
|
21
21
|
|
22
22
|
def []=(key, value)
|
23
|
-
@
|
23
|
+
@redis.call 'SET', @scope[key], Marshal.dump(value)
|
24
24
|
end
|
25
25
|
|
26
26
|
def delete(key)
|
27
|
-
@
|
27
|
+
@redis.call 'DEL', @scope[key]
|
28
28
|
end
|
29
29
|
|
30
30
|
def delete_cascade(key)
|
31
|
-
@
|
32
|
-
@
|
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
|
-
@
|
36
|
+
@redis.call('KEYS', @scope['*']).map { |k| Key[k].remove_first }
|
37
37
|
end
|
38
38
|
|
39
39
|
def synchronize(key)
|
40
|
-
while @
|
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
|
-
@
|
45
|
+
@redis.call 'DEL', @scope[key][LOCKED]
|
46
46
|
end
|
47
47
|
|
48
48
|
def connection_args
|
49
|
-
[@scope, @
|
49
|
+
[@scope, @redis.url]
|
50
50
|
end
|
51
51
|
|
52
52
|
def self.connect(*args)
|
data/lib/asynchronic/process.rb
CHANGED
@@ -11,7 +11,7 @@ module Asynchronic
|
|
11
11
|
aborted: :finalized_at
|
12
12
|
}
|
13
13
|
|
14
|
-
ATTRIBUTE_NAMES = [:type, :name, :queue, :status, :dependencies, :data, :result, :error] | TIME_TRACKING_MAP.values.uniq
|
14
|
+
ATTRIBUTE_NAMES = [:type, :name, :queue, :status, :dependencies, :data, :result, :error, :connection_name] | TIME_TRACKING_MAP.values.uniq
|
15
15
|
|
16
16
|
CANCELED_ERROR_MESSAGE = 'Canceled'
|
17
17
|
|
@@ -47,6 +47,10 @@ module Asynchronic
|
|
47
47
|
abort! CANCELED_ERROR_MESSAGE
|
48
48
|
end
|
49
49
|
|
50
|
+
def dead?
|
51
|
+
(running? && !connected?) || processes.any?(&:dead?)
|
52
|
+
end
|
53
|
+
|
50
54
|
def destroy
|
51
55
|
data_store.delete_cascade
|
52
56
|
end
|
@@ -75,7 +79,7 @@ module Asynchronic
|
|
75
79
|
|
76
80
|
def processes
|
77
81
|
data_store.scoped(:processes).keys.
|
78
|
-
select { |k| k.sections.count == 2 && k.match(
|
82
|
+
select { |k| k.sections.count == 2 && k.match(/\|name$/) }.
|
79
83
|
sort.map { |k| Process.new environment, id[:processes][k.remove_last] }
|
80
84
|
end
|
81
85
|
|
@@ -208,6 +212,8 @@ module Asynchronic
|
|
208
212
|
end
|
209
213
|
|
210
214
|
def run
|
215
|
+
self.connection_name = Asynchronic.connection_name
|
216
|
+
|
211
217
|
if root.aborted?
|
212
218
|
abort!
|
213
219
|
else
|
@@ -215,6 +221,7 @@ module Asynchronic
|
|
215
221
|
self.result = job.call
|
216
222
|
waiting!
|
217
223
|
end
|
224
|
+
|
218
225
|
rescue Exception => ex
|
219
226
|
message = "Failed process #{type} (#{id})\n#{ex.class} #{ex.message}\n#{ex.backtrace.join("\n")}"
|
220
227
|
Asynchronic.logger.error('Asynchronic') { message }
|
@@ -249,5 +256,9 @@ module Asynchronic
|
|
249
256
|
parent.queue if parent
|
250
257
|
end
|
251
258
|
|
259
|
+
def connected?
|
260
|
+
connection_name && environment.queue_engine.active_connections.include?(connection_name)
|
261
|
+
end
|
262
|
+
|
252
263
|
end
|
253
264
|
end
|
@@ -1,17 +1,14 @@
|
|
1
1
|
module Asynchronic
|
2
2
|
module QueueEngine
|
3
3
|
class Ost
|
4
|
-
|
4
|
+
|
5
5
|
attr_reader :default_queue
|
6
6
|
|
7
7
|
def initialize(options={})
|
8
|
-
|
9
|
-
@default_queue = options
|
8
|
+
@redis = Redic.new(*Array(options[:redis]))
|
9
|
+
@default_queue = options.fetch(:default_queue, Asynchronic.default_queue)
|
10
10
|
@queues ||= Hash.new { |h,k| h[k] = Queue.new k }
|
11
|
-
|
12
|
-
|
13
|
-
def default_queue
|
14
|
-
@default_queue ||= Asynchronic.default_queue
|
11
|
+
@keep_alive_thread = notify_keep_alive
|
15
12
|
end
|
16
13
|
|
17
14
|
def [](name)
|
@@ -19,12 +16,12 @@ module Asynchronic
|
|
19
16
|
end
|
20
17
|
|
21
18
|
def queues
|
22
|
-
(@queues.values.map(&:key) | redis.
|
19
|
+
(@queues.values.map(&:key) | @redis.call('KEYS', 'ost:*')).map { |q| q.to_s[4..-1].to_sym }
|
23
20
|
end
|
24
21
|
|
25
22
|
def clear
|
26
23
|
@queues.clear
|
27
|
-
redis.
|
24
|
+
@redis.call('KEYS', 'ost:*').each { |k| @redis.call('DEL', k) }
|
28
25
|
end
|
29
26
|
|
30
27
|
def listener
|
@@ -35,21 +32,32 @@ module Asynchronic
|
|
35
32
|
true
|
36
33
|
end
|
37
34
|
|
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?)
|
39
|
+
end
|
40
|
+
|
38
41
|
private
|
39
42
|
|
40
|
-
def
|
41
|
-
|
43
|
+
def notify_keep_alive
|
44
|
+
Thread.new do
|
45
|
+
loop do
|
46
|
+
@redis.call 'CLIENT', 'SETNAME', Asynchronic.connection_name
|
47
|
+
sleep Asynchronic.keep_alive_timeout
|
48
|
+
end
|
49
|
+
end
|
42
50
|
end
|
43
51
|
|
44
52
|
|
45
53
|
class Queue < ::Ost::Queue
|
46
54
|
|
47
55
|
def pop
|
48
|
-
key
|
56
|
+
redis.call 'RPOP', key
|
49
57
|
end
|
50
58
|
|
51
59
|
def empty?
|
52
|
-
|
60
|
+
redis.call('EXISTS', key) == 0
|
53
61
|
end
|
54
62
|
|
55
63
|
def size
|
@@ -68,7 +76,7 @@ module Asynchronic
|
|
68
76
|
def listen(queue, &block)
|
69
77
|
@current_queue = queue
|
70
78
|
Asynchronic.retry_execution(self.class, 'listen') do
|
71
|
-
queue.each
|
79
|
+
queue.each(&block)
|
72
80
|
end
|
73
81
|
end
|
74
82
|
|
data/lib/asynchronic/version.rb
CHANGED
@@ -1,3 +1,3 @@
|
|
1
1
|
module Asynchronic
|
2
|
-
VERSION = '
|
3
|
-
end
|
2
|
+
VERSION = '2.0.0'
|
3
|
+
end
|
data/lib/asynchronic/worker.rb
CHANGED
@@ -23,7 +23,7 @@ class Asynchronic::Worker
|
|
23
23
|
end
|
24
24
|
|
25
25
|
def stop
|
26
|
-
Asynchronic.logger.info('Asynchronic') { "Stopping worker of #{
|
26
|
+
Asynchronic.logger.info('Asynchronic') { "Stopping worker of #{queue_name} (#{Process.pid})" }
|
27
27
|
listener.stop
|
28
28
|
end
|
29
29
|
|
@@ -22,19 +22,19 @@ module DataStoreExamples
|
|
22
22
|
end
|
23
23
|
|
24
24
|
it 'Delete cascade' do
|
25
|
-
data_store[Key[:key_1]] = 1
|
26
|
-
data_store[Key[:key_1][:key_1_1]] = 2
|
27
|
-
data_store[Key[:key_1][:key_1_2]] = 3
|
28
|
-
data_store[Key[:key_2]] = 4
|
29
|
-
data_store[Key[:key_2][:key_2_1]] = 5
|
30
|
-
data_store[Key[:key_2][:key_2_2]] = 6
|
25
|
+
data_store[Asynchronic::DataStore::Key[:key_1]] = 1
|
26
|
+
data_store[Asynchronic::DataStore::Key[:key_1][:key_1_1]] = 2
|
27
|
+
data_store[Asynchronic::DataStore::Key[:key_1][:key_1_2]] = 3
|
28
|
+
data_store[Asynchronic::DataStore::Key[:key_2]] = 4
|
29
|
+
data_store[Asynchronic::DataStore::Key[:key_2][:key_2_1]] = 5
|
30
|
+
data_store[Asynchronic::DataStore::Key[:key_2][:key_2_2]] = 6
|
31
31
|
|
32
|
-
data_store.delete_cascade Key[:key_1]
|
32
|
+
data_store.delete_cascade Asynchronic::DataStore::Key[:key_1]
|
33
33
|
|
34
34
|
data_store.keys.sort.must_equal [
|
35
|
-
Key[:key_2],
|
36
|
-
Key[:key_2][:key_2_1],
|
37
|
-
Key[:key_2][:key_2_2]
|
35
|
+
Asynchronic::DataStore::Key[:key_2],
|
36
|
+
Asynchronic::DataStore::Key[:key_2][:key_2_1],
|
37
|
+
Asynchronic::DataStore::Key[:key_2][:key_2_2]
|
38
38
|
]
|
39
39
|
end
|
40
40
|
|
data/spec/expectations.rb
CHANGED
@@ -75,6 +75,10 @@ module MiniTest::Assertions
|
|
75
75
|
process.finalized_at.must_be_instance_of Time
|
76
76
|
end
|
77
77
|
|
78
|
+
def assert_have_connection_name(process)
|
79
|
+
process.connection_name.must_equal Asynchronic.connection_name
|
80
|
+
end
|
81
|
+
|
78
82
|
end
|
79
83
|
|
80
84
|
Asynchronic::QueueEngine::InMemory::Queue.infect_an_assertion :assert_enqueued, :must_enqueued
|
@@ -85,4 +89,5 @@ Asynchronic::Process.infect_an_assertion :assert_be_pending, :must_be_pending, :
|
|
85
89
|
Asynchronic::Process.infect_an_assertion :assert_be_queued, :must_be_queued, :unary
|
86
90
|
Asynchronic::Process.infect_an_assertion :assert_be_waiting, :must_be_waiting, :unary
|
87
91
|
Asynchronic::Process.infect_an_assertion :assert_be_completed, :must_be_completed, :unary
|
88
|
-
Asynchronic::Process.infect_an_assertion :assert_be_aborted, :must_be_aborted, :unary
|
92
|
+
Asynchronic::Process.infect_an_assertion :assert_be_aborted, :must_be_aborted, :unary
|
93
|
+
Asynchronic::Process.infect_an_assertion :assert_have_connection_name, :must_have_connection_name, :unary
|
data/spec/facade_spec.rb
CHANGED
@@ -64,4 +64,16 @@ describe Asynchronic, 'Facade' do
|
|
64
64
|
Asynchronic.garbage_collector.must_be_instance_of Asynchronic::GarbageCollector
|
65
65
|
end
|
66
66
|
|
67
|
+
it 'Redis data store sync timeout' do
|
68
|
+
Asynchronic.redis_data_store_sync_timeout.must_equal 0.01
|
69
|
+
end
|
70
|
+
|
71
|
+
it 'Keep alive timeout' do
|
72
|
+
Asynchronic.keep_alive_timeout.must_equal 0.1
|
73
|
+
end
|
74
|
+
|
75
|
+
it 'Connection name' do
|
76
|
+
Asynchronic.connection_name.must_equal "HOST=#{Socket.gethostname},PID=#{::Process.pid}"
|
77
|
+
end
|
78
|
+
|
67
79
|
end
|
data/spec/minitest_helper.rb
CHANGED
@@ -10,17 +10,22 @@ module LifeCycleExamples
|
|
10
10
|
end
|
11
11
|
|
12
12
|
def create(type, params={})
|
13
|
-
env.create_process
|
13
|
+
env.create_process(type, params).tap do |process|
|
14
|
+
process.must_be_initialized
|
15
|
+
end
|
14
16
|
end
|
15
17
|
|
16
18
|
def execute(queue)
|
17
|
-
env.load_process(queue.pop)
|
19
|
+
process = env.load_process(queue.pop)
|
20
|
+
process.execute
|
21
|
+
process.must_have_connection_name
|
22
|
+
process.wont_be :dead?
|
23
|
+
process.send(:connected?).must_be_true
|
18
24
|
end
|
19
25
|
|
20
26
|
it 'Basic' do
|
21
27
|
process = create BasicJob, input: 1
|
22
28
|
|
23
|
-
process.must_be_initialized
|
24
29
|
process.must_have_params input: 1
|
25
30
|
queue.must_be_empty
|
26
31
|
|
@@ -39,7 +44,6 @@ module LifeCycleExamples
|
|
39
44
|
it 'Sequential' do
|
40
45
|
process = create SequentialJob, input: 50
|
41
46
|
|
42
|
-
process.must_be_initialized
|
43
47
|
process.must_have_params input: 50
|
44
48
|
queue.must_be_empty
|
45
49
|
|
@@ -77,7 +81,6 @@ module LifeCycleExamples
|
|
77
81
|
it 'Graph' do
|
78
82
|
process = create GraphJob, input: 100
|
79
83
|
|
80
|
-
process.must_be_initialized
|
81
84
|
process.must_have_params input: 100
|
82
85
|
queue.must_be_empty
|
83
86
|
|
@@ -133,7 +136,6 @@ module LifeCycleExamples
|
|
133
136
|
it 'Parallel' do
|
134
137
|
process = create ParallelJob, input: 10, times: 3
|
135
138
|
|
136
|
-
process.must_be_initialized
|
137
139
|
process.must_have_params input: 10, times: 3
|
138
140
|
queue.must_be_empty
|
139
141
|
|
@@ -167,7 +169,6 @@ module LifeCycleExamples
|
|
167
169
|
it 'Nested' do
|
168
170
|
process = create NestedJob, input: 4
|
169
171
|
|
170
|
-
process.must_be_initialized
|
171
172
|
process.must_have_params input: 4
|
172
173
|
queue.must_be_empty
|
173
174
|
|
@@ -207,7 +208,6 @@ module LifeCycleExamples
|
|
207
208
|
it 'Alias' do
|
208
209
|
process = create AliasJob
|
209
210
|
|
210
|
-
process.must_be_initialized
|
211
211
|
queue.must_be_empty
|
212
212
|
|
213
213
|
process.enqueue
|
@@ -261,7 +261,6 @@ module LifeCycleExamples
|
|
261
261
|
it 'Custom queue' do
|
262
262
|
process = create CustomQueueJob, input: 'hello'
|
263
263
|
|
264
|
-
process.must_be_initialized
|
265
264
|
process.must_have_params input: 'hello'
|
266
265
|
|
267
266
|
env.queue(:queue_1).must_be_empty
|
@@ -302,7 +301,6 @@ module LifeCycleExamples
|
|
302
301
|
it 'Exception' do
|
303
302
|
process = create ExceptionJob
|
304
303
|
|
305
|
-
process.must_be_initialized
|
306
304
|
queue.must_be_empty
|
307
305
|
|
308
306
|
process.enqueue
|
@@ -320,7 +318,6 @@ module LifeCycleExamples
|
|
320
318
|
it 'Inner exception' do
|
321
319
|
process = create InnerExceptionJob
|
322
320
|
|
323
|
-
process.must_be_initialized
|
324
321
|
queue.must_be_empty
|
325
322
|
|
326
323
|
process.enqueue
|
@@ -348,7 +345,6 @@ module LifeCycleExamples
|
|
348
345
|
it 'Forward reference' do
|
349
346
|
process = create ForwardReferenceJob
|
350
347
|
|
351
|
-
process.must_be_initialized
|
352
348
|
queue.must_be_empty
|
353
349
|
|
354
350
|
process.enqueue
|
@@ -391,7 +387,6 @@ module LifeCycleExamples
|
|
391
387
|
it 'Job with retries' do
|
392
388
|
process = create WithRetriesJob
|
393
389
|
|
394
|
-
process.must_be_initialized
|
395
390
|
queue.must_be_empty
|
396
391
|
|
397
392
|
process.enqueue
|
@@ -604,7 +599,7 @@ module LifeCycleExamples
|
|
604
599
|
pid_1 = process_1.id
|
605
600
|
pid_2 = process_2.id
|
606
601
|
|
607
|
-
data_store.keys.select { |k| k.start_with? pid_1 }.count.must_equal
|
602
|
+
data_store.keys.select { |k| k.start_with? pid_1 }.count.must_equal 38
|
608
603
|
data_store.keys.select { |k| k.start_with? pid_2 }.count.must_equal 7
|
609
604
|
|
610
605
|
process_1.destroy
|
@@ -628,8 +623,8 @@ module LifeCycleExamples
|
|
628
623
|
process_1.must_be_completed
|
629
624
|
process_2.must_be_waiting
|
630
625
|
|
631
|
-
data_store.keys.select { |k| k.start_with? pid_1 }.count.must_equal
|
632
|
-
data_store.keys.select { |k| k.start_with? pid_2 }.count.must_equal
|
626
|
+
data_store.keys.select { |k| k.start_with? pid_1 }.count.must_equal 53
|
627
|
+
data_store.keys.select { |k| k.start_with? pid_2 }.count.must_equal 38
|
633
628
|
|
634
629
|
gc = Asynchronic::GarbageCollector.new env, 0.001
|
635
630
|
|
@@ -651,13 +646,12 @@ module LifeCycleExamples
|
|
651
646
|
gc.start
|
652
647
|
|
653
648
|
data_store.keys.select { |k| k.start_with? pid_1 }.count.must_equal 0
|
654
|
-
data_store.keys.select { |k| k.start_with? pid_2 }.count.must_equal
|
649
|
+
data_store.keys.select { |k| k.start_with? pid_2 }.count.must_equal 38
|
655
650
|
end
|
656
651
|
|
657
652
|
it 'Before finalize hook when completed' do
|
658
653
|
process = create BeforeFinalizeCompletedJob
|
659
654
|
|
660
|
-
process.must_be_initialized
|
661
655
|
queue.must_be_empty
|
662
656
|
|
663
657
|
process.enqueue
|
@@ -675,7 +669,6 @@ module LifeCycleExamples
|
|
675
669
|
it 'Before finalize hook when aborted' do
|
676
670
|
process = create BeforeFinalizeAbortedJob
|
677
671
|
|
678
|
-
process.must_be_initialized
|
679
672
|
queue.must_be_empty
|
680
673
|
|
681
674
|
process.enqueue
|
@@ -693,7 +686,6 @@ module LifeCycleExamples
|
|
693
686
|
it 'Before finalize raises exception and aborts' do
|
694
687
|
process = create BeforeFinalizeRaisesExceptionJob
|
695
688
|
|
696
|
-
process.must_be_initialized
|
697
689
|
queue.must_be_empty
|
698
690
|
|
699
691
|
process.enqueue
|
@@ -711,7 +703,6 @@ module LifeCycleExamples
|
|
711
703
|
it 'Before finalize raises exception on aborted job' do
|
712
704
|
process = create BeforeFinalizeExceptionOnAbortedJob
|
713
705
|
|
714
|
-
process.must_be_initialized
|
715
706
|
queue.must_be_empty
|
716
707
|
|
717
708
|
process.enqueue
|
@@ -31,17 +31,23 @@ module QueueEngineExamples
|
|
31
31
|
end
|
32
32
|
|
33
33
|
it 'Listener' do
|
34
|
-
|
35
|
-
|
34
|
+
Timeout.timeout(5) do
|
35
|
+
queue.push 'msg_1'
|
36
|
+
queue.push 'msg_2'
|
36
37
|
|
37
|
-
|
38
|
+
messages = []
|
38
39
|
|
39
|
-
|
40
|
-
|
41
|
-
|
40
|
+
listener.listen(queue) do |msg|
|
41
|
+
messages << msg
|
42
|
+
listener.stop if queue.empty?
|
43
|
+
end
|
44
|
+
|
45
|
+
messages.must_equal %w(msg_1 msg_2)
|
42
46
|
end
|
47
|
+
end
|
43
48
|
|
44
|
-
|
49
|
+
it 'Active connections' do
|
50
|
+
engine.active_connections.must_equal [Asynchronic.connection_name]
|
45
51
|
end
|
46
52
|
|
47
53
|
end
|
@@ -34,5 +34,9 @@ describe Asynchronic::QueueEngine::Synchronic do
|
|
34
34
|
process.must_be_completed
|
35
35
|
process.result.must_equal '10%' => 20, '20%' => 40
|
36
36
|
end
|
37
|
-
|
37
|
+
|
38
|
+
it 'Active connections' do
|
39
|
+
Asynchronic.queue_engine.active_connections.must_equal [Asynchronic.connection_name]
|
40
|
+
end
|
41
|
+
|
38
42
|
end
|
metadata
CHANGED
@@ -1,43 +1,29 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: asynchronic
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 2.0.0
|
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-
|
11
|
+
date: 2019-06-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
|
-
- !ruby/object:Gem::Dependency
|
14
|
-
name: redis
|
15
|
-
requirement: !ruby/object:Gem::Requirement
|
16
|
-
requirements:
|
17
|
-
- - "~>"
|
18
|
-
- !ruby/object:Gem::Version
|
19
|
-
version: '3.0'
|
20
|
-
type: :runtime
|
21
|
-
prerelease: false
|
22
|
-
version_requirements: !ruby/object:Gem::Requirement
|
23
|
-
requirements:
|
24
|
-
- - "~>"
|
25
|
-
- !ruby/object:Gem::Version
|
26
|
-
version: '3.0'
|
27
13
|
- !ruby/object:Gem::Dependency
|
28
14
|
name: ost
|
29
15
|
requirement: !ruby/object:Gem::Requirement
|
30
16
|
requirements:
|
31
17
|
- - "~>"
|
32
18
|
- !ruby/object:Gem::Version
|
33
|
-
version: '0
|
19
|
+
version: '1.0'
|
34
20
|
type: :runtime
|
35
21
|
prerelease: false
|
36
22
|
version_requirements: !ruby/object:Gem::Requirement
|
37
23
|
requirements:
|
38
24
|
- - "~>"
|
39
25
|
- !ruby/object:Gem::Version
|
40
|
-
version: '0
|
26
|
+
version: '1.0'
|
41
27
|
- !ruby/object:Gem::Dependency
|
42
28
|
name: class_config
|
43
29
|
requirement: !ruby/object:Gem::Requirement
|