chantier 2.0.0 → 2.1.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: 1ad91f24a7bd64070ce2d9943a1340a786348fa5
4
- data.tar.gz: ae221e941dd3d8994644e4179d7684e60c9cf234
3
+ metadata.gz: df6ec380493c999c846abeb870e45720b428f35b
4
+ data.tar.gz: 354b14a6eab4824369ea8bc52e0c45ab1f034d2a
5
5
  SHA512:
6
- metadata.gz: 0752ee267d03dbb4b9abfa5541d11faf302b0c549355b1ea1b0dc6a6d5dfaabf7f3f42beaf72705faada50c7bab2d8b30b9fbeaa1f59b8c6e50640d99833745a
7
- data.tar.gz: 2249fe8959c9b8086e2c68960738e78bfd79b6cb78b3d7f3889df1a721fe75a996731cce407f1f29d7a326bf1adbb0931c02c926a07ca67c0489ec96a7a178a2
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.0.0 ruby lib
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.0.0"
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 = "2014-08-07"
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
@@ -1,5 +1,5 @@
1
1
  module Chantier
2
- VERSION = '2.0.0'
2
+ VERSION = '2.1.0'
3
3
  require_relative 'process_pool'
4
4
  require_relative 'process_pool_with_kill'
5
5
  require_relative 'thread_pool'
@@ -86,6 +86,7 @@ module Chantier::FailurePolicies
86
86
  end
87
87
 
88
88
  def limit_reached?
89
+ return false unless ((@failures + @successes) > 4)
89
90
  ratio = @failures.to_f / (@failures + @successes)
90
91
  (ratio * 100) >= @threshold
91
92
  end
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 "Reached error limit (last error was #{@last_representative_exception.inspect})"
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 process slots have been freed.
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
@@ -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('Reached error limit (last error was #<RuntimeError: I am such a failure>)')
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.0.0
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: 2014-08-07 00:00:00.000000000 Z
11
+ date: 2015-10-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rspec