process-group 0.2.1 → 1.0.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: 372a5e01e0eec6598278b7b6d9d7752f59190b66
4
- data.tar.gz: ef2061f5503a85c60a0e56a81efaff25b1d95dc6
3
+ metadata.gz: eb7a4e8773cff719edfa1b553e7773c34d6a3537
4
+ data.tar.gz: b746a13f2d670c5a3051c1d076da83b38461d5ee
5
5
  SHA512:
6
- metadata.gz: ffff6097b47894fef08ad2e083d0a5834929393d278085b00c3e6a5dfc508801266c0a2752f437feea24b7b1f43fcc9f368584df45d3dbcdf00fd04e87c97dcb
7
- data.tar.gz: bff7b9a0140d6e6c5655824ac4b7110b75a2095b281a1d5e143870dac6dfc6454d792e7a21f4fc1403de4bae53243863796296afd75bf9906521ba887fea878c
6
+ metadata.gz: 5d475c34015705d9a7fd8fbca38bff1e1964338e9c210c6dc901da1ce40393d690cccaee4df3201ac4badff5151e9c74ef76f3c51a6f69ee2fc7d10ba7789d68
7
+ data.tar.gz: 0f9d5c41fb03e194cee54272a87a3d0c3df2f6251587648ef1cc04d3d3a9a8e5e109e0519ae62e02de460d30d92833a5f65655b0c06fe1ce7af485470de9c157
@@ -0,0 +1,9 @@
1
+
2
+ SimpleCov.start do
3
+ add_filter "/spec/"
4
+ end
5
+
6
+ if ENV['TRAVIS']
7
+ require 'coveralls'
8
+ Coveralls.wear!
9
+ end
@@ -1,5 +1,7 @@
1
1
  language: ruby
2
+ sudo: false
2
3
  rvm:
3
- - "1.9"
4
4
  - "2.0"
5
5
  - "2.1"
6
+ - "2.2"
7
+ env: COVERAGE=true
data/Gemfile CHANGED
@@ -3,3 +3,7 @@ source 'https://rubygems.org'
3
3
  # Specify your gem's dependencies in process-pool.gemspec
4
4
  gemspec
5
5
 
6
+ group :test do
7
+ gem 'simplecov'
8
+ gem 'coveralls', require: false
9
+ end
data/README.md CHANGED
@@ -2,7 +2,9 @@
2
2
 
3
3
  `Process::Group` allows for multiple fibers to run system processes concurrently with minimal overhead.
4
4
 
5
- [![Build Status](https://travis-ci.org/ioquatix/process-group.svg?branch=master)](https://travis-ci.org/ioquatix/process-group)
5
+ [![Build Status](https://secure.travis-ci.org/ioquatix/process-group.svg)](http://travis-ci.org/ioquatix/process-group)
6
+ [![Code Climate](https://codeclimate.com/github/ioquatix/process-group.svg)](https://codeclimate.com/github/ioquatix/process-group)
7
+ [![Coverage Status](https://coveralls.io/repos/ioquatix/process-group/badge.svg)](https://coveralls.io/r/ioquatix/process-group)
6
8
 
7
9
  ## Installation
8
10
 
@@ -101,7 +103,7 @@ If there are no running processes, this is a no-op (rather than an error).
101
103
 
102
104
  #### Handling Interrupts
103
105
 
104
- `Process::Graph` transparently handles `Interrupt` when raised within a `Fiber`. If `Interrupt` is raised, all children processes will be sent `kill(:INT)` and we will wait for all children to complete, but without resuming the controlling fibers. If `Interrupt` is raised during this process, children will be sent `kill(:TERM)`. After calling `Interrupt`, the fibers will not be resumed.
106
+ `Process::Group` transparently handles `Interrupt` when raised within a `Fiber`. If `Interrupt` is raised, all children processes will be sent `kill(:INT)` and we will wait for all children to complete, but without resuming the controlling fibers. If `Interrupt` is raised during this process, children will be sent `kill(:TERM)`. After calling `Interrupt`, the fibers will not be resumed.
105
107
 
106
108
  ### Process Timeout
107
109
 
data/Rakefile CHANGED
@@ -1,6 +1,8 @@
1
1
  require "bundler/gem_tasks"
2
2
  require "rspec/core/rake_task"
3
3
 
4
- RSpec::Core::RakeTask.new(:spec)
4
+ RSpec::Core::RakeTask.new(:spec) do |task|
5
+ task.rspec_opts = ["--require", "simplecov"] if ENV['COVERAGE']
6
+ end
5
7
 
6
8
  task :default => :spec
@@ -48,7 +48,8 @@ module Process
48
48
  class Fork
49
49
  def initialize(block, options, fiber = Fiber.current)
50
50
  @options = options
51
- @block = block
51
+
52
+ raise ArgumentError.new("Fork requires a block!") unless @block = block
52
53
 
53
54
  @fiber = fiber
54
55
  end
@@ -73,9 +74,11 @@ module Process
73
74
  end
74
75
 
75
76
  # Create a new process group. Can specify `options[:limit]` which limits the maximum number of concurrent processes.
76
- def initialize(options = {})
77
+ def initialize(limit: nil)
78
+ @pid = Process.pid
79
+
77
80
  @queue = []
78
- @limit = options[:limit]
81
+ @limit = limit
79
82
 
80
83
  @running = {}
81
84
  @fiber = nil
@@ -109,14 +112,11 @@ module Process
109
112
  end.resume
110
113
  end
111
114
 
112
- def spawn(*arguments)
113
- # Could be nice to use ** splat, but excludes ruby < 2.0.
114
- options = Hash === arguments.last ? arguments.pop : {}
115
-
115
+ def spawn(*arguments, **options)
116
116
  append! Command.new(arguments, options)
117
117
  end
118
118
 
119
- def fork(options = {}, &block)
119
+ def fork(**options, &block)
120
120
  append! Fork.new(block, options)
121
121
  end
122
122
 
@@ -136,6 +136,8 @@ module Process
136
136
 
137
137
  # Wait for all processes to finish, naturally would schedule any fibers which are currently blocked.
138
138
  def wait
139
+ raise ArgumentError.new("Cannot call Process::Group#wait from child process!") unless @pid == Process.pid
140
+
139
141
  while running?
140
142
  process, status = wait_one
141
143
 
@@ -196,7 +198,7 @@ module Process
196
198
  else
197
199
  pid = process.run(:pgroup => @pgid)
198
200
  end
199
-
201
+
200
202
  @running[pid] = process
201
203
  end
202
204
  end
@@ -20,6 +20,6 @@
20
20
 
21
21
  module Process
22
22
  class Group
23
- VERSION = "0.2.1"
23
+ VERSION = "1.0.0"
24
24
  end
25
25
  end
@@ -20,7 +20,9 @@ Gem::Specification.new do |spec|
20
20
  spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
21
21
  spec.require_paths = ["lib"]
22
22
 
23
+ spec.required_ruby_version = '>= 2.0'
24
+
23
25
  spec.add_development_dependency "bundler", "~> 1.3"
24
- spec.add_development_dependency "rspec", "~> 3.0.0.rc1"
26
+ spec.add_development_dependency "rspec", "~> 3.3.0"
25
27
  spec.add_development_dependency "rake"
26
28
  end
@@ -49,6 +49,9 @@ module Process::Group::ForkSpec
49
49
 
50
50
  Fiber.new do
51
51
  result = group.fork do
52
+ # Don't print out a backtrace when Ruby invariably exits due to the execption below:
53
+ $stderr.reopen('/dev/null', 'w')
54
+
52
55
  raise Interrupt
53
56
  end
54
57
 
@@ -144,7 +144,7 @@ module Process::Group::InterruptSpec
144
144
  end_time = Time.now
145
145
 
146
146
  expect(checkpoint).to be == 'ABCE'
147
- expect(end_time - start_time).to be_within(0.1).of 4.0
147
+ expect(end_time - start_time).to be_within(0.2).of 4.0
148
148
  end
149
149
  end
150
150
  end
@@ -0,0 +1,46 @@
1
+ # Copyright, 2015, by Samuel G. D. Williams. <http://www.codeotaku.com>
2
+ #
3
+ # Permission is hereby granted, free of charge, to any person obtaining a copy
4
+ # of this software and associated documentation files (the "Software"), to deal
5
+ # in the Software without restriction, including without limitation the rights
6
+ # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7
+ # copies of the Software, and to permit persons to whom the Software is
8
+ # furnished to do so, subject to the following conditions:
9
+ #
10
+ # The above copyright notice and this permission notice shall be included in
11
+ # all copies or substantial portions of the Software.
12
+ #
13
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
+ # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
+ # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
+ # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
+ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19
+ # THE SOFTWARE.
20
+
21
+ require 'process/group'
22
+
23
+ module Process::Group::LoadSpec
24
+ describe Process::Group do
25
+ it "should only run a limited number of processes" do
26
+ group = Process::Group.new(limit: 5)
27
+
28
+ expect(group.available?).to be_truthy
29
+ expect(group.blocking?).to be_falsey
30
+
31
+ 5.times do
32
+ Fiber.new do
33
+ result = group.fork do
34
+ exit(0)
35
+ end
36
+
37
+ expect(result.exitstatus).to be == 0
38
+ end.resume
39
+ end
40
+
41
+ expect(group.blocking?).to be_truthy
42
+
43
+ group.wait
44
+ end
45
+ end
46
+ end
@@ -0,0 +1,57 @@
1
+ # Copyright, 2015, by Samuel G. D. Williams. <http://www.codeotaku.com>
2
+ #
3
+ # Permission is hereby granted, free of charge, to any person obtaining a copy
4
+ # of this software and associated documentation files (the "Software"), to deal
5
+ # in the Software without restriction, including without limitation the rights
6
+ # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7
+ # copies of the Software, and to permit persons to whom the Software is
8
+ # furnished to do so, subject to the following conditions:
9
+ #
10
+ # The above copyright notice and this permission notice shall be included in
11
+ # all copies or substantial portions of the Software.
12
+ #
13
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
+ # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
+ # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
+ # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
+ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19
+ # THE SOFTWARE.
20
+
21
+ module Process::Group::ProcessSpec
22
+ describe Process do
23
+ it "default fork exit status should be 0" do
24
+ pid = fork do
25
+ end
26
+
27
+ Process.waitpid(pid)
28
+
29
+ expect($?.exitstatus).to be == 0
30
+ end
31
+
32
+ it "should fork and return exit status correctly" do
33
+ pid = fork do
34
+ exit(1)
35
+ end
36
+
37
+ Process.waitpid(pid)
38
+
39
+ expect($?.exitstatus).to be == 1
40
+ end
41
+
42
+ # This is currently broken on Rubinius.
43
+ it "should be okay to use fork within a fiber" do
44
+ pid = nil
45
+
46
+ Fiber.new do
47
+ pid = fork do
48
+ exit(2)
49
+ end
50
+ end.resume
51
+
52
+ Process.waitpid(pid)
53
+
54
+ expect($?.exitstatus).to be == 2
55
+ end
56
+ end
57
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: process-group
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Samuel Williams
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-06-04 00:00:00.000000000 Z
11
+ date: 2015-08-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -30,14 +30,14 @@ dependencies:
30
30
  requirements:
31
31
  - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: 3.0.0.rc1
33
+ version: 3.3.0
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: 3.0.0.rc1
40
+ version: 3.3.0
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: rake
43
43
  requirement: !ruby/object:Gem::Requirement
@@ -62,6 +62,7 @@ extensions: []
62
62
  extra_rdoc_files: []
63
63
  files:
64
64
  - ".gitignore"
65
+ - ".simplecov"
65
66
  - ".travis.yml"
66
67
  - Gemfile
67
68
  - README.md
@@ -73,6 +74,8 @@ files:
73
74
  - spec/process/group/fork_spec.rb
74
75
  - spec/process/group/interrupt_spec.rb
75
76
  - spec/process/group/io_spec.rb
77
+ - spec/process/group/load_spec.rb
78
+ - spec/process/group/process_spec.rb
76
79
  - spec/process/group/spawn_spec.rb
77
80
  homepage: ''
78
81
  licenses:
@@ -86,7 +89,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
86
89
  requirements:
87
90
  - - ">="
88
91
  - !ruby/object:Gem::Version
89
- version: '0'
92
+ version: '2.0'
90
93
  required_rubygems_version: !ruby/object:Gem::Requirement
91
94
  requirements:
92
95
  - - ">="
@@ -102,4 +105,6 @@ test_files:
102
105
  - spec/process/group/fork_spec.rb
103
106
  - spec/process/group/interrupt_spec.rb
104
107
  - spec/process/group/io_spec.rb
108
+ - spec/process/group/load_spec.rb
109
+ - spec/process/group/process_spec.rb
105
110
  - spec/process/group/spawn_spec.rb