asynchronic 3.0.3 → 4.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (39) hide show
  1. checksums.yaml +4 -4
  2. data/.travis.yml +1 -0
  3. data/README.md +1 -1
  4. data/lib/asynchronic.rb +8 -0
  5. data/lib/asynchronic/data_store/in_memory.rb +17 -15
  6. data/lib/asynchronic/data_store/key.rb +3 -3
  7. data/lib/asynchronic/data_store/lazy_value.rb +5 -3
  8. data/lib/asynchronic/data_store/redis.rb +22 -14
  9. data/lib/asynchronic/data_store/scoped_store.rb +18 -19
  10. data/lib/asynchronic/environment.rb +3 -3
  11. data/lib/asynchronic/error.rb +2 -3
  12. data/lib/asynchronic/job.rb +12 -12
  13. data/lib/asynchronic/notifier/broadcaster.rb +8 -4
  14. data/lib/asynchronic/process.rb +35 -32
  15. data/lib/asynchronic/queue_engine/in_memory.rb +17 -11
  16. data/lib/asynchronic/queue_engine/ost.rb +7 -5
  17. data/lib/asynchronic/queue_engine/synchronic.rb +19 -7
  18. data/lib/asynchronic/version.rb +1 -1
  19. data/lib/asynchronic/worker.rb +7 -10
  20. data/spec/data_store/data_store_examples.rb +17 -9
  21. data/spec/data_store/in_memory_spec.rb +0 -2
  22. data/spec/data_store/key_spec.rb +1 -1
  23. data/spec/data_store/lazy_value_examples.rb +7 -5
  24. data/spec/data_store/redis_spec.rb +4 -10
  25. data/spec/expectations.rb +2 -2
  26. data/spec/facade_spec.rb +3 -3
  27. data/spec/jobs.rb +10 -10
  28. data/spec/minitest_helper.rb +5 -12
  29. data/spec/process/life_cycle_examples.rb +24 -22
  30. data/spec/process/life_cycle_in_memory_spec.rb +0 -1
  31. data/spec/process/life_cycle_redis_spec.rb +0 -1
  32. data/spec/queue_engine/in_memory_spec.rb +1 -3
  33. data/spec/queue_engine/ost_spec.rb +1 -7
  34. data/spec/queue_engine/queue_engine_examples.rb +17 -9
  35. data/spec/queue_engine/synchronic_spec.rb +1 -1
  36. data/spec/worker/in_memory_spec.rb +1 -2
  37. data/spec/worker/redis_spec.rb +0 -6
  38. data/spec/worker/worker_examples.rb +6 -4
  39. metadata +3 -3
@@ -9,9 +9,11 @@ require 'expectations'
9
9
  require 'timeout'
10
10
  require 'pry-nav'
11
11
 
12
- class Module
13
- include Minitest::Spec::DSL
14
- end
12
+ require_relative 'data_store/data_store_examples'
13
+ require_relative 'data_store/lazy_value_examples'
14
+ require_relative 'process/life_cycle_examples'
15
+ require_relative 'queue_engine/queue_engine_examples'
16
+ require_relative 'worker/worker_examples'
15
17
 
16
18
  Asynchronic.logger.level = Logger::FATAL
17
19
 
@@ -20,13 +22,4 @@ class Minitest::Spec
20
22
  Asynchronic.restore_default_configuration
21
23
  Asynchronic.default_queue = :asynchronic_test
22
24
  end
23
- end
24
-
25
- module Asynchronic::DataStore::Helper
26
- def dump
27
- puts 'DataStore:'
28
- each do |k,v|
29
- puts "#{k}: #{v}"
30
- end
31
- end
32
25
  end
@@ -1,5 +1,7 @@
1
1
  module LifeCycleExamples
2
-
2
+
3
+ extend Minitest::Spec::DSL
4
+
3
5
  let(:env) { Asynchronic::Environment.new queue_engine, data_store, notifier }
4
6
 
5
7
  let(:queue) { env.default_queue }
@@ -29,7 +31,7 @@ module LifeCycleExamples
29
31
 
30
32
  process.must_have_connection_name
31
33
  process.wont_be :dead?
32
-
34
+
33
35
  process.send(:connected?).must_be_true
34
36
 
35
37
  env.queue_engine.stub(:active_connections, ->() { raise 'Forced error' }) do
@@ -138,7 +140,7 @@ module LifeCycleExamples
138
140
  process[GraphJob::Total].must_be_pending
139
141
  process[GraphJob::Total].must_have_params '10%' => nil, '20%' => nil
140
142
  queue.must_enqueued process[GraphJob::Sum]
141
-
143
+
142
144
  execute queue
143
145
 
144
146
  process.must_be_waiting
@@ -294,7 +296,7 @@ module LifeCycleExamples
294
296
  process[:word_3].result.must_equal 'Take it easy'
295
297
  queue.must_be_empty
296
298
  end
297
-
299
+
298
300
  it 'Custom queue' do
299
301
  process = create CustomQueueJob, input: 'hello'
300
302
 
@@ -308,7 +310,7 @@ module LifeCycleExamples
308
310
 
309
311
  process.must_be_queued
310
312
  process.processes.must_be_empty
311
-
313
+
312
314
  env.queue(:queue_1).must_enqueued process
313
315
  env.queue(:queue_2).must_be_empty
314
316
  env.queue(:queue_3).must_be_empty
@@ -318,7 +320,7 @@ module LifeCycleExamples
318
320
  process.must_be_waiting
319
321
  process[CustomQueueJob::Reverse].must_be_queued
320
322
  process[CustomQueueJob::Reverse].must_have_params input: 'hello'
321
-
323
+
322
324
  env.queue(:queue_1).must_be_empty
323
325
  env.queue(:queue_2).must_enqueued process[CustomQueueJob::Reverse]
324
326
  env.queue(:queue_3).must_be_empty
@@ -329,7 +331,7 @@ module LifeCycleExamples
329
331
  process.result.must_equal 'olleh'
330
332
  process[CustomQueueJob::Reverse].must_be_completed
331
333
  process[CustomQueueJob::Reverse].result.must_equal 'olleh'
332
-
334
+
333
335
  env.queue(:queue_1).must_be_empty
334
336
  env.queue(:queue_2).must_be_empty
335
337
  env.queue(:queue_3).must_be_empty
@@ -485,7 +487,7 @@ module LifeCycleExamples
485
487
 
486
488
  it 'Data' do
487
489
  process = create DataJob, input: 1
488
-
490
+
489
491
  process.enqueue
490
492
  execute queue
491
493
 
@@ -497,7 +499,7 @@ module LifeCycleExamples
497
499
  it 'Nested job with error in child' do
498
500
  process = create NestedJobWithErrorInChildJob
499
501
 
500
- process.enqueue
502
+ process.enqueue
501
503
 
502
504
  Timeout.timeout(1) do
503
505
  until process.status == :aborted
@@ -511,17 +513,17 @@ module LifeCycleExamples
511
513
  it 'Nested job with error in parent' do
512
514
  process = create NestedJobWithErrorInParentJob
513
515
 
514
- process.enqueue
516
+ process.enqueue
515
517
 
516
518
  execute queue
517
-
519
+
518
520
  process.real_error.must_equal "Error in parent"
519
521
  end
520
522
 
521
523
  it 'Abort queued After error' do
522
524
  process = create AbortQueuedAfterErrorJob
523
525
 
524
- process.enqueue
526
+ process.enqueue
525
527
 
526
528
  execute queue
527
529
 
@@ -602,27 +604,27 @@ module LifeCycleExamples
602
604
 
603
605
  execute queue
604
606
 
605
- process.full_status.must_equal 'NestedJob' => :waiting,
607
+ process.full_status.must_equal 'NestedJob' => :waiting,
606
608
  'NestedJob::Level1' => :queued
607
609
 
608
610
  execute queue
609
611
 
610
- process.full_status.must_equal 'NestedJob' => :waiting,
611
- 'NestedJob::Level1' => :waiting,
612
+ process.full_status.must_equal 'NestedJob' => :waiting,
613
+ 'NestedJob::Level1' => :waiting,
612
614
  'NestedJob::Level1::Level2' => :queued
613
615
 
614
616
  process.cancel!
615
617
 
616
618
  process.real_error.must_equal Asynchronic::Process::CANCELED_ERROR_MESSAGE
617
619
 
618
- process.full_status.must_equal 'NestedJob' => :aborted,
619
- 'NestedJob::Level1' => :waiting,
620
+ process.full_status.must_equal 'NestedJob' => :aborted,
621
+ 'NestedJob::Level1' => :waiting,
620
622
  'NestedJob::Level1::Level2' => :queued
621
623
 
622
624
  execute queue
623
625
 
624
- process.full_status.must_equal 'NestedJob' => :aborted,
625
- 'NestedJob::Level1' => :aborted,
626
+ process.full_status.must_equal 'NestedJob' => :aborted,
627
+ 'NestedJob::Level1' => :aborted,
626
628
  'NestedJob::Level1::Level2' => :aborted
627
629
  end
628
630
 
@@ -650,7 +652,7 @@ module LifeCycleExamples
650
652
  process_1 = create AliasJob
651
653
  process_1.enqueue
652
654
  4.times { execute queue }
653
-
655
+
654
656
  process_2 = create AliasJob
655
657
  process_2.enqueue
656
658
  execute queue
@@ -670,7 +672,7 @@ module LifeCycleExamples
670
672
  data_store.keys.select { |k| k.start_with? pid_3 }.count.must_equal 7
671
673
 
672
674
  gc = Asynchronic::GarbageCollector.new env, 0.001
673
-
675
+
674
676
  gc.add_condition('Finalized', &:finalized?)
675
677
  gc.add_condition('Waiting', &:waiting?)
676
678
  gc.add_condition('Exception') { raise 'Invalid condition' }
@@ -678,7 +680,7 @@ module LifeCycleExamples
678
680
  gc.conditions_names.must_equal ['Finalized', 'Waiting', 'Exception']
679
681
 
680
682
  gc.remove_condition 'Waiting'
681
-
683
+
682
684
  gc.conditions_names.must_equal ['Finalized', 'Exception']
683
685
 
684
686
  Thread.new do
@@ -1,5 +1,4 @@
1
1
  require 'minitest_helper'
2
- require_relative './life_cycle_examples.rb'
3
2
 
4
3
  describe Asynchronic::Process, 'Life cycle - InMemory' do
5
4
 
@@ -1,5 +1,4 @@
1
1
  require 'minitest_helper'
2
- require_relative './life_cycle_examples.rb'
3
2
 
4
3
  describe Asynchronic::Process, 'Life cycle - Redis' do
5
4
 
@@ -1,11 +1,9 @@
1
1
  require 'minitest_helper'
2
- require_relative './queue_engine_examples'
3
2
 
4
3
  describe Asynchronic::QueueEngine::InMemory do
5
4
 
6
5
  let(:engine) { Asynchronic::QueueEngine::InMemory.new }
7
- let(:listener) { Asynchronic::QueueEngine::InMemory::Listener.new }
8
6
 
9
7
  include QueueEngineExamples
10
-
8
+
11
9
  end
@@ -1,19 +1,13 @@
1
1
  require 'minitest_helper'
2
- require_relative './queue_engine_examples'
3
2
 
4
3
  describe Asynchronic::QueueEngine::Ost do
5
4
 
6
5
  let(:engine) { Asynchronic::QueueEngine::Ost.new }
7
- let(:listener) { Asynchronic::QueueEngine::Ost::Listener.new }
8
6
 
9
- before do
10
- engine.clear
11
- end
12
-
13
7
  include QueueEngineExamples
14
8
 
15
9
  it 'Engine and queues use same redis connection' do
16
10
  engine.redis.must_equal queue.redis
17
11
  end
18
-
12
+
19
13
  end
@@ -1,26 +1,34 @@
1
1
  module QueueEngineExamples
2
-
2
+
3
+ extend Minitest::Spec::DSL
4
+
3
5
  let(:queue) { engine[:test_queue] }
4
6
 
7
+ let(:listener) { engine.listener }
8
+
9
+ after do
10
+ engine.clear
11
+ end
12
+
5
13
  it 'Engine' do
6
- engine.queues.must_be_empty
7
-
14
+ engine.queue_names.must_be_empty
15
+
8
16
  queue = engine[:test_engine]
9
17
  queue.must_be_instance_of engine.class.const_get(:Queue)
10
- engine.queues.must_equal [:test_engine]
11
-
18
+ engine.queue_names.must_equal [:test_engine]
19
+
12
20
  engine[:test_engine].must_equal queue
13
-
21
+
14
22
  engine.clear
15
- engine.queues.must_be_empty
23
+ engine.queue_names.must_be_empty
16
24
  end
17
25
 
18
26
  it 'Queue (push/pop)' do
19
27
  queue.must_be_empty
20
-
28
+
21
29
  queue.push 'msg_1'
22
30
  queue.push 'msg_2'
23
-
31
+
24
32
  queue.size.must_equal 2
25
33
  queue.to_a.must_equal %w(msg_1 msg_2)
26
34
 
@@ -22,7 +22,7 @@ describe Asynchronic::QueueEngine::Synchronic do
22
22
  Asynchronic.queue_engine.stub BasicJob do |process|
23
23
  process.params[:input] + 19
24
24
  end
25
-
25
+
26
26
  pid = BasicJob.enqueue input: 1
27
27
  process = Asynchronic[pid]
28
28
  process.result.must_equal 20
@@ -1,5 +1,4 @@
1
1
  require 'minitest_helper'
2
- require_relative './worker_examples'
3
2
 
4
3
  describe Asynchronic::Worker, 'InMemory' do
5
4
 
@@ -8,5 +7,5 @@ describe Asynchronic::Worker, 'InMemory' do
8
7
  let(:notifier) { Asynchronic::Notifier::InMemory.new }
9
8
 
10
9
  include WorkerExamples
11
-
10
+
12
11
  end
@@ -1,5 +1,4 @@
1
1
  require 'minitest_helper'
2
- require_relative './worker_examples'
3
2
 
4
3
  describe Asynchronic::Worker, 'Redis' do
5
4
 
@@ -7,11 +6,6 @@ describe Asynchronic::Worker, 'Redis' do
7
6
  let(:data_store) { Asynchronic::DataStore::Redis.new :asynchronic_test}
8
7
  let(:notifier) { Asynchronic::Notifier::Broadcaster.new }
9
8
 
10
- after do
11
- data_store.clear
12
- queue_engine.clear
13
- end
14
-
15
9
  include WorkerExamples
16
10
 
17
11
  end
@@ -1,5 +1,7 @@
1
1
  module WorkerExamples
2
2
 
3
+ extend Minitest::Spec::DSL
4
+
3
5
  let(:env) { Asynchronic::Environment.new queue_engine, data_store, notifier }
4
6
  let(:queue_name) { :test_worker }
5
7
  let(:queue) { env.queue queue_name }
@@ -27,7 +29,7 @@ module WorkerExamples
27
29
 
28
30
  Thread.new do
29
31
  loop { break if queue.empty? }
30
- worker.stop
32
+ worker.stop
31
33
  end
32
34
 
33
35
  worker.start
@@ -45,10 +47,10 @@ module WorkerExamples
45
47
 
46
48
  Asynchronic::Worker.start :test_worker do |worker|
47
49
  loop { break if worker.queue.empty? }
48
- worker.stop
50
+ worker.stop
49
51
  end
50
-
51
- processes.each { |p| p.must_be :completed? }
52
+
53
+ processes.each { |p| p.must_be :completed? }
52
54
  end
53
55
 
54
56
  end
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.3
4
+ version: 4.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: 2021-03-26 00:00:00.000000000 Z
11
+ date: 2021-06-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: ost
@@ -297,7 +297,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
297
297
  - !ruby/object:Gem::Version
298
298
  version: '0'
299
299
  requirements: []
300
- rubygems_version: 3.0.6
300
+ rubygems_version: 3.0.8
301
301
  signing_key:
302
302
  specification_version: 4
303
303
  summary: DSL for asynchronic pipeline using queues over Redis