asynchronic 1.5.2 → 1.6.0

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: 91d93cee903cf5734fc88048a090ba518d4c65e1
4
- data.tar.gz: 441eb434a52aaacdc469c95f186a4aa2718af4b7
3
+ metadata.gz: 7e70899d480cd9a9c3a99bf747e93a2e62e9c55b
4
+ data.tar.gz: 41078d0bf32c17cf370d5eb3451dbbf66663fca5
5
5
  SHA512:
6
- metadata.gz: 9d1c471352876eaf7ef6a62369a32dcfa1bfe9dc75e872def46291c12b8a09cd9ac3722b532d51b0d4d0a40837515756f37409d02d2c560463eaa3d002f8b8da
7
- data.tar.gz: 25d56122f0a8e13847b247de73b4bb2d30859f4a02588a9719838a4aba3430c9d583e4641dd7e1db4340874610842eff36587086dd2d39e3466ac352445fb903
6
+ metadata.gz: 857050561908c34ac116d4374ede47e22822244236cb3086e64579282360e7cdd017d8f2254f72bd0b2f7e25b51d65b78c00a78d1a794e5d7ac9fc075d99a01c
7
+ data.tar.gz: f9d0618a300f6623402828ee739484bf07959e47cb2ad2ff5f5f41678b49fa1c6b250dc6ba0eb9acf9eae32b728e223626b6ef259eefa3322ae8ab630a52e5b8
data/.travis.yml CHANGED
@@ -8,6 +8,7 @@ rvm:
8
8
  - 2.3.0
9
9
  - 2.4.0
10
10
  - 2.5.0
11
+ - 2.6.0
11
12
  - jruby-1.7.25
12
13
  - jruby-9.1.7.0
13
14
  - ruby-head
@@ -20,7 +21,8 @@ matrix:
20
21
  - rvm: jruby-head
21
22
 
22
23
  before_install:
23
- - gem install bundler
24
+ - rvm all-gemsets do gem uninstall bundler -ax || true
25
+ - gem install bundler -v "< 2"
24
26
 
25
27
  services:
26
28
  - redis-server
@@ -32,6 +32,10 @@ module Asynchronic
32
32
  nil
33
33
  end
34
34
 
35
+ def get(key)
36
+ process.get key
37
+ end
38
+
35
39
  def set(key, value)
36
40
  process.set key, value
37
41
  end
@@ -66,7 +66,7 @@ module Asynchronic
66
66
  end
67
67
 
68
68
  def job
69
- type.new self
69
+ @job ||= type.new self
70
70
  end
71
71
 
72
72
  def [](process_name)
@@ -135,6 +135,10 @@ module Asynchronic
135
135
  self.class.create environment, type, params.merge(id: id[:processes][processes.count])
136
136
  end
137
137
 
138
+ def get(key)
139
+ data[key]
140
+ end
141
+
138
142
  def set(key, value)
139
143
  self.data = self.data.merge key => value
140
144
  end
@@ -188,6 +192,7 @@ module Asynchronic
188
192
 
189
193
  STATUSES.each do |status|
190
194
  define_method "#{status}!" do
195
+ job.before_finalize if [:completed, :aborted].include?(status) && job.respond_to?(:before_finalize)
191
196
  self.status = status
192
197
  end
193
198
  end
@@ -64,6 +64,9 @@ module Asynchronic
64
64
  @block.call @process
65
65
  end
66
66
 
67
+ def before_finalize
68
+ end
69
+
67
70
  end
68
71
 
69
72
  end
@@ -1,3 +1,3 @@
1
1
  module Asynchronic
2
- VERSION = '1.5.2'
2
+ VERSION = '1.6.0'
3
3
  end
data/spec/jobs.rb CHANGED
@@ -360,4 +360,26 @@ class AbortQueuedAfertErrorJob < Asynchronic::Job
360
360
  nil
361
361
  end
362
362
  end
363
- end
363
+ end
364
+
365
+
366
+ class BeforeFinalizeCompletedJob < Asynchronic::Job
367
+ def call
368
+ set :key, 0
369
+ end
370
+
371
+ def before_finalize
372
+ set :key, get(:key) + 10
373
+ end
374
+ end
375
+
376
+ class BeforeFinalizeAbortedJob < Asynchronic::Job
377
+ def call
378
+ set :key, 1
379
+ raise 'Forced error'
380
+ end
381
+
382
+ def before_finalize
383
+ set :key, get(:key) + 1
384
+ end
385
+ end
@@ -654,4 +654,40 @@ module LifeCycleExamples
654
654
  data_store.keys.select { |k| k.start_with? pid_2 }.count.must_equal 37
655
655
  end
656
656
 
657
+ it 'Before finalize hook when completed' do
658
+ process = create BeforeFinalizeCompletedJob
659
+
660
+ process.must_be_initialized
661
+ queue.must_be_empty
662
+
663
+ process.enqueue
664
+
665
+ process.must_be_queued
666
+ queue.must_enqueued process
667
+
668
+ execute queue
669
+
670
+ process.must_be_completed
671
+ process.get(:key).must_equal 10
672
+ queue.must_be_empty
673
+ end
674
+
675
+ it 'Before finalize hook when aborted' do
676
+ process = create BeforeFinalizeAbortedJob
677
+
678
+ process.must_be_initialized
679
+ queue.must_be_empty
680
+
681
+ process.enqueue
682
+
683
+ process.must_be_queued
684
+ queue.must_enqueued process
685
+
686
+ execute queue
687
+
688
+ process.must_be_aborted
689
+ process.get(:key).must_equal 2
690
+ queue.must_be_empty
691
+ end
692
+
657
693
  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: 1.5.2
4
+ version: 1.6.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: 2018-12-14 00:00:00.000000000 Z
11
+ date: 2019-01-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: redis