chantier 2.0.0 → 2.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/chantier.gemspec +3 -3
- data/lib/chantier.rb +1 -1
- data/lib/failure_policies.rb +1 -0
- data/lib/process_pool.rb +5 -1
- data/lib/thread_pool.rb +8 -3
- data/spec/failure_policy_by_percentage_spec.rb +12 -0
- data/spec/thread_pool_spec.rb +3 -2
- 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: df6ec380493c999c846abeb870e45720b428f35b
|
4
|
+
data.tar.gz: 354b14a6eab4824369ea8bc52e0c45ab1f034d2a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 55d0986d79834e5c7efec3cf0f850a7da33915fd37471960cf921644a29c67436b3d4a39df62b973cbab8206cb635ac34ff9726fdb4d50a14e5e174ac9151fd5
|
7
|
+
data.tar.gz: 5b03b35c3161c98a8db5a23b3b83290b2d530182c39bcad262bef955089f99db645bd7ad1bf492cbb3cb14357fa71c5c877c10f23df30286c1ae22c39eafe378
|
data/chantier.gemspec
CHANGED
@@ -2,16 +2,16 @@
|
|
2
2
|
# DO NOT EDIT THIS FILE DIRECTLY
|
3
3
|
# Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
|
4
4
|
# -*- encoding: utf-8 -*-
|
5
|
-
# stub: chantier 2.
|
5
|
+
# stub: chantier 2.1.0 ruby lib
|
6
6
|
|
7
7
|
Gem::Specification.new do |s|
|
8
8
|
s.name = "chantier"
|
9
|
-
s.version = "2.
|
9
|
+
s.version = "2.1.0"
|
10
10
|
|
11
11
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
12
12
|
s.require_paths = ["lib"]
|
13
13
|
s.authors = ["Julik Tarkhanov"]
|
14
|
-
s.date = "
|
14
|
+
s.date = "2015-10-29"
|
15
15
|
s.description = " Process your jobs in parallel with a simple table of processes or threads "
|
16
16
|
s.email = "me@julik.nl"
|
17
17
|
s.extra_rdoc_files = [
|
data/lib/chantier.rb
CHANGED
data/lib/failure_policies.rb
CHANGED
data/lib/process_pool.rb
CHANGED
@@ -26,7 +26,6 @@
|
|
26
26
|
#
|
27
27
|
# Can be rewritten using Threads if operation on JVM/Rubinius will be feasible.
|
28
28
|
class Chantier::ProcessPool
|
29
|
-
|
30
29
|
# The manager uses loops in a few places. By doing a little sleep()
|
31
30
|
# in those loops we can yield process control back to the OS which brings
|
32
31
|
# the CPU usage of the managing process to small numbers. If you just do
|
@@ -63,6 +62,11 @@ class Chantier::ProcessPool
|
|
63
62
|
block_until_complete!
|
64
63
|
end
|
65
64
|
|
65
|
+
# Launch copies of the given task in all available slots for this Pool.
|
66
|
+
def fork_task_in_all_slots(&blk)
|
67
|
+
@pids.times { fork_task(&blk) }
|
68
|
+
end
|
69
|
+
|
66
70
|
# Run the given block in a forked subprocess. This method will block
|
67
71
|
# the thread it is called from until a slot in the process table
|
68
72
|
# becomes free. Once that happens, the given block will be forked off
|
data/lib/thread_pool.rb
CHANGED
@@ -26,7 +26,6 @@
|
|
26
26
|
#
|
27
27
|
# Can be rewritten using Threads if operation on JVM/Rubinius will be feasible.
|
28
28
|
class Chantier::ThreadPool
|
29
|
-
|
30
29
|
# The manager uses loops in a few places. By doing a little sleep()
|
31
30
|
# in those loops we can yield process control back to the OS which brings
|
32
31
|
# the CPU usage of the managing process to small numbers. If you just do
|
@@ -49,6 +48,11 @@ class Chantier::ThreadPool
|
|
49
48
|
@last_representative_exception = nil
|
50
49
|
end
|
51
50
|
|
51
|
+
# Launch copies of the given task in all available slots for this Pool.
|
52
|
+
def fork_task_in_all_slots(&blk)
|
53
|
+
@threads.times { fork_task(&blk) }
|
54
|
+
end
|
55
|
+
|
52
56
|
# Distributes the elements in the given Enumerable to parallel workers,
|
53
57
|
# N workers at a time. The method will return once all the workers for all
|
54
58
|
# the elements of the Enumerable have terminated.
|
@@ -71,7 +75,7 @@ class Chantier::ThreadPool
|
|
71
75
|
# becomes free.
|
72
76
|
def fork_task(&blk)
|
73
77
|
if @failure_policy.limit_reached?
|
74
|
-
raise
|
78
|
+
raise @last_representative_exception
|
75
79
|
end
|
76
80
|
|
77
81
|
destination_slot_idx = nil
|
@@ -103,7 +107,8 @@ class Chantier::ThreadPool
|
|
103
107
|
@threads.any?{|e| e && e.respond_to?(:alive?) && e.alive? }
|
104
108
|
end
|
105
109
|
|
106
|
-
# Analogous to Process.wait or wait_all - will block until all of the
|
110
|
+
# Analogous to Process.wait or wait_all - will block until all of the
|
111
|
+
# threads have terminated
|
107
112
|
def block_until_complete!
|
108
113
|
@threads.map do |e|
|
109
114
|
if e.respond_to?(:join) && e.alive?
|
@@ -24,4 +24,16 @@ describe Chantier::FailurePolicies::Percentage do
|
|
24
24
|
policy.arm!
|
25
25
|
expect(policy).not_to be_limit_reached
|
26
26
|
end
|
27
|
+
|
28
|
+
it 'does not trigger until it has been called at least 4 times' do
|
29
|
+
policy = described_class.new(50)
|
30
|
+
policy.arm!
|
31
|
+
|
32
|
+
2.times { policy.failure! }
|
33
|
+
expect(policy).not_to be_limit_reached
|
34
|
+
2.times { policy.failure! }
|
35
|
+
expect(policy).not_to be_limit_reached
|
36
|
+
1.times { policy.failure! }
|
37
|
+
expect(policy).to be_limit_reached
|
38
|
+
end
|
27
39
|
end
|
data/spec/thread_pool_spec.rb
CHANGED
@@ -46,15 +46,16 @@ describe Chantier::ThreadPool do
|
|
46
46
|
end
|
47
47
|
end
|
48
48
|
|
49
|
+
RandomError = Class.new(RuntimeError)
|
49
50
|
context 'with failures' do
|
50
51
|
it 'raises after 4 failures' do
|
51
52
|
fp = Chantier::FailurePolicies::Count.new(4)
|
52
53
|
under_test = described_class.new(num_workers=3, failure_policy: fp)
|
53
54
|
expect {
|
54
55
|
15.times do
|
55
|
-
under_test.fork_task { raise "I am such a failure" }
|
56
|
+
under_test.fork_task { raise RandomError, "I am such a failure" }
|
56
57
|
end
|
57
|
-
}.to raise_error('
|
58
|
+
}.to raise_error(RandomError, 'I am such a failure')
|
58
59
|
end
|
59
60
|
|
60
61
|
it 'runs through the jobs if max_failures is not given' do
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: chantier
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.
|
4
|
+
version: 2.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Julik Tarkhanov
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2015-10-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rspec
|