process-group 1.0.0 → 1.0.1

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: eb7a4e8773cff719edfa1b553e7773c34d6a3537
4
- data.tar.gz: b746a13f2d670c5a3051c1d076da83b38461d5ee
3
+ metadata.gz: 28a68aa53cd296412dd77cdca5a9c8b000269439
4
+ data.tar.gz: 49777327e43bbddda6e17a2b13776227693d115d
5
5
  SHA512:
6
- metadata.gz: 5d475c34015705d9a7fd8fbca38bff1e1964338e9c210c6dc901da1ce40393d690cccaee4df3201ac4badff5151e9c74ef76f3c51a6f69ee2fc7d10ba7789d68
7
- data.tar.gz: 0f9d5c41fb03e194cee54272a87a3d0c3df2f6251587648ef1cc04d3d3a9a8e5e109e0519ae62e02de460d30d92833a5f65655b0c06fe1ce7af485470de9c157
6
+ metadata.gz: 508765b5658d4fbb032c7f43f36a5a9c26e4fbbfc379295398d3ac08e9da12bab9440cb9002bd052d9eaaba5abbbd9ee970f8a290ceaab144ad682e53e95ebfb
7
+ data.tar.gz: 0f7d655bd81259b92c757342ff71aee743209e33dbb3c1a71e4b4facd0c4dac5de706a01735c4afd964feb6b52429e8d6b07e706db992408a7da81f599b5a4e9
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --format documentation
data/.travis.yml CHANGED
@@ -1,7 +1,14 @@
1
1
  language: ruby
2
2
  sudo: false
3
3
  rvm:
4
- - "2.0"
5
- - "2.1"
6
- - "2.2"
4
+ - 2.0.0
5
+ - 2.1.8
6
+ - 2.2.4
7
+ - 2.3.0
8
+ - ruby-head
9
+ - rbx-2
7
10
  env: COVERAGE=true
11
+ matrix:
12
+ allow_failures:
13
+ - rvm: "rbx-2"
14
+
data/README.md CHANGED
@@ -5,6 +5,8 @@
5
5
  [![Build Status](https://secure.travis-ci.org/ioquatix/process-group.svg)](http://travis-ci.org/ioquatix/process-group)
6
6
  [![Code Climate](https://codeclimate.com/github/ioquatix/process-group.svg)](https://codeclimate.com/github/ioquatix/process-group)
7
7
  [![Coverage Status](https://coveralls.io/repos/ioquatix/process-group/badge.svg)](https://coveralls.io/r/ioquatix/process-group)
8
+ [![Documentation](http://img.shields.io/badge/yard-docs-blue.svg)](http://www.rubydoc.info/gems/process-group)
9
+ [![Code](http://img.shields.io/badge/github-code-blue.svg)](https://github.com/ioquatix/process-group)
8
10
 
9
11
  ## Installation
10
12
 
data/lib/process/group.rb CHANGED
@@ -23,6 +23,7 @@ require 'fiber'
23
23
  module Process
24
24
  # A group of tasks which can be run asynchrnously using fibers. Someone must call Group#wait to ensure that all fibers eventually resume.
25
25
  class Group
26
+ # Executes a command using Process.spawn with the given arguments and options.
26
27
  class Command
27
28
  def initialize(arguments, options, fiber = Fiber.current)
28
29
  @arguments = arguments
@@ -45,6 +46,7 @@ module Process
45
46
  end
46
47
  end
47
48
 
49
+ # Runs a given block using a forked process.
48
50
  class Fork
49
51
  def initialize(block, options, fiber = Fiber.current)
50
52
  @options = options
@@ -73,8 +75,10 @@ module Process
73
75
  end
74
76
  end
75
77
 
76
- # Create a new process group. Can specify `options[:limit]` which limits the maximum number of concurrent processes.
78
+ # Create a new process group. Can specify `limit:` which limits the maximum number of concurrent processes.
77
79
  def initialize(limit: nil)
80
+ raise ArgumentError.new("Limit must be nil (unlimited) or > 0") unless limit == nil or limit > 0
81
+
78
82
  @pid = Process.pid
79
83
 
80
84
  @queue = []
@@ -99,11 +103,12 @@ module Process
99
103
  -@pgid
100
104
  end
101
105
 
106
+ # Are there processes currently running?
102
107
  def running?
103
108
  @running.size > 0
104
109
  end
105
110
 
106
- # Run a process, arguments have same meaning as Process#spawn.
111
+ # Run a process in a new fiber, arguments have same meaning as Process#spawn.
107
112
  def run(*arguments)
108
113
  Fiber.new do
109
114
  exit_status = self.spawn(*arguments)
@@ -112,15 +117,17 @@ module Process
112
117
  end.resume
113
118
  end
114
119
 
120
+ # Run a specific command as a child process.
115
121
  def spawn(*arguments, **options)
116
122
  append! Command.new(arguments, options)
117
123
  end
118
124
 
125
+ # Fork a block as a child process.
119
126
  def fork(**options, &block)
120
127
  append! Fork.new(block, options)
121
128
  end
122
129
 
123
- # Whether not not calling run would be scheduled immediately.
130
+ # Whether or not #spawn, #fork or #run can be scheduled immediately.
124
131
  def available?
125
132
  if @limit
126
133
  @running.size < @limit
@@ -129,12 +136,12 @@ module Process
129
136
  end
130
137
  end
131
138
 
132
- # Whether or not calling run would block the caller.
139
+ # Whether or not calling #spawn, #fork or #run would block the caller fiber (i.e. call Fiber.yield).
133
140
  def blocking?
134
141
  not available?
135
142
  end
136
143
 
137
- # Wait for all processes to finish, naturally would schedule any fibers which are currently blocked.
144
+ # Wait for all running and queued processes to finish.
138
145
  def wait
139
146
  raise ArgumentError.new("Cannot call Process::Group#wait from child process!") unless @pid == Process.pid
140
147
 
@@ -168,8 +175,8 @@ module Process
168
175
  wait_all
169
176
  end
170
177
 
171
- # Send a signal to all processes.
172
- def kill(signal)
178
+ # Send a signal to all currently running processes. No-op unless #running?
179
+ def kill(signal = :INT)
173
180
  if running?
174
181
  Process.kill(signal, id)
175
182
  end
@@ -177,6 +184,7 @@ module Process
177
184
 
178
185
  private
179
186
 
187
+ # Append a process to the queue and schedule it for execution if possible.
180
188
  def append!(process)
181
189
  @queue << process
182
190
 
@@ -20,6 +20,6 @@
20
20
 
21
21
  module Process
22
22
  class Group
23
- VERSION = "1.0.0"
23
+ VERSION = "1.0.1"
24
24
  end
25
25
  end
@@ -12,7 +12,7 @@ Gem::Specification.new do |spec|
12
12
  Manages a unix process group for running multiple processes, keeps track of multiple processes and leverages fibers to provide predictable behaviour in complicated process-based scripts.
13
13
  EOF
14
14
  spec.summary = %q{Run processes concurrently in separate fibers with predictable behaviour.}
15
- spec.homepage = ""
15
+ spec.homepage = "https://github.com/ioquatix/process-group"
16
16
  spec.license = "MIT"
17
17
 
18
18
  spec.files = `git ls-files`.split($/)
@@ -23,6 +23,6 @@ Gem::Specification.new do |spec|
23
23
  spec.required_ruby_version = '>= 2.0'
24
24
 
25
25
  spec.add_development_dependency "bundler", "~> 1.3"
26
- spec.add_development_dependency "rspec", "~> 3.3.0"
26
+ spec.add_development_dependency "rspec", "~> 3.4.0"
27
27
  spec.add_development_dependency "rake"
28
28
  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: 1.0.0
4
+ version: 1.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Samuel Williams
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-08-22 00:00:00.000000000 Z
11
+ date: 2016-01-09 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.3.0
33
+ version: 3.4.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.3.0
40
+ version: 3.4.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
+ - ".rspec"
65
66
  - ".simplecov"
66
67
  - ".travis.yml"
67
68
  - Gemfile
@@ -77,7 +78,7 @@ files:
77
78
  - spec/process/group/load_spec.rb
78
79
  - spec/process/group/process_spec.rb
79
80
  - spec/process/group/spawn_spec.rb
80
- homepage: ''
81
+ homepage: https://github.com/ioquatix/process-group
81
82
  licenses:
82
83
  - MIT
83
84
  metadata: {}
@@ -97,7 +98,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
97
98
  version: '0'
98
99
  requirements: []
99
100
  rubyforge_project:
100
- rubygems_version: 2.2.2
101
+ rubygems_version: 2.4.6
101
102
  signing_key:
102
103
  specification_version: 4
103
104
  summary: Run processes concurrently in separate fibers with predictable behaviour.