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 +4 -4
- data/.travis.yml +3 -1
- data/lib/asynchronic/job.rb +4 -0
- data/lib/asynchronic/process.rb +6 -1
- data/lib/asynchronic/queue_engine/synchronic.rb +3 -0
- data/lib/asynchronic/version.rb +1 -1
- data/spec/jobs.rb +23 -1
- data/spec/process/life_cycle_examples.rb +36 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7e70899d480cd9a9c3a99bf747e93a2e62e9c55b
|
4
|
+
data.tar.gz: 41078d0bf32c17cf370d5eb3451dbbf66663fca5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
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
|
data/lib/asynchronic/job.rb
CHANGED
data/lib/asynchronic/process.rb
CHANGED
@@ -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
|
data/lib/asynchronic/version.rb
CHANGED
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.
|
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:
|
11
|
+
date: 2019-01-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: redis
|