pwork 0.1.1 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- metadata +7 -26
- data/.bundle/config +0 -2
- data/.gitignore +0 -5
- data/.rspec +0 -3
- data/CODE_OF_CONDUCT.md +0 -49
- data/Gemfile +0 -4
- data/Gemfile.lock +0 -43
- data/LICENSE.txt +0 -21
- data/README.md +0 -95
- data/Rakefile +0 -2
- data/bin/console +0 -14
- data/bin/setup +0 -8
- data/lib/pwork.rb +0 -71
- data/lib/pwork/version.rb +0 -3
- data/pwork.gemspec +0 -26
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 15f4c4a2ca14320dff30454942391f11899747b3
|
4
|
+
data.tar.gz: 6e7236ea011bcf47d87cf46d6c89e8ede2155bb8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 705e7f465d1673a350251eece6c535315e3f741dcea389603ced860914aca98619733301848c5f1503ebed904594cbf5bfb36632d8400588b1eabfc8c247115d
|
7
|
+
data.tar.gz: 38dd75cbedf92bd3ada6f3225e17f41f89509c74cc989322add0d51ca318ea0c04b84f50d6e55f9300338e25cd319e6839ddf4b1d47631d51bc9730a1bcedb82
|
metadata
CHANGED
@@ -1,29 +1,29 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: pwork
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 1.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- vaughanbrittonage
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2017-10-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- - "
|
17
|
+
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version:
|
19
|
+
version: '0'
|
20
20
|
type: :development
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- - "
|
24
|
+
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version:
|
26
|
+
version: '0'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: rake
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -73,26 +73,7 @@ email:
|
|
73
73
|
executables: []
|
74
74
|
extensions: []
|
75
75
|
extra_rdoc_files: []
|
76
|
-
files:
|
77
|
-
- ".bundle/config"
|
78
|
-
- ".gitignore"
|
79
|
-
- ".idea/.name"
|
80
|
-
- ".idea/.rakeTasks"
|
81
|
-
- ".idea/encodings.xml"
|
82
|
-
- ".idea/misc.xml"
|
83
|
-
- ".idea/vcs.xml"
|
84
|
-
- ".rspec"
|
85
|
-
- CODE_OF_CONDUCT.md
|
86
|
-
- Gemfile
|
87
|
-
- Gemfile.lock
|
88
|
-
- LICENSE.txt
|
89
|
-
- README.md
|
90
|
-
- Rakefile
|
91
|
-
- bin/console
|
92
|
-
- bin/setup
|
93
|
-
- lib/pwork.rb
|
94
|
-
- lib/pwork/version.rb
|
95
|
-
- pwork.gemspec
|
76
|
+
files: []
|
96
77
|
homepage: https://github.com/vaughanbrittonsage/pwork
|
97
78
|
licenses:
|
98
79
|
- MIT
|
data/.bundle/config
DELETED
data/.gitignore
DELETED
data/.rspec
DELETED
data/CODE_OF_CONDUCT.md
DELETED
@@ -1,49 +0,0 @@
|
|
1
|
-
# Contributor Code of Conduct
|
2
|
-
|
3
|
-
As contributors and maintainers of this project, and in the interest of
|
4
|
-
fostering an open and welcoming community, we pledge to respect all people who
|
5
|
-
contribute through reporting issues, posting feature requests, updating
|
6
|
-
documentation, submitting pull requests or patches, and other activities.
|
7
|
-
|
8
|
-
We are committed to making participation in this project a harassment-free
|
9
|
-
experience for everyone, regardless of level of experience, gender, gender
|
10
|
-
identity and expression, sexual orientation, disability, personal appearance,
|
11
|
-
body size, race, ethnicity, age, religion, or nationality.
|
12
|
-
|
13
|
-
Examples of unacceptable behavior by participants include:
|
14
|
-
|
15
|
-
* The use of sexualized language or imagery
|
16
|
-
* Personal attacks
|
17
|
-
* Trolling or insulting/derogatory comments
|
18
|
-
* Public or private harassment
|
19
|
-
* Publishing other's private information, such as physical or electronic
|
20
|
-
addresses, without explicit permission
|
21
|
-
* Other unethical or unprofessional conduct
|
22
|
-
|
23
|
-
Project maintainers have the right and responsibility to remove, edit, or
|
24
|
-
reject comments, commits, code, wiki edits, issues, and other contributions
|
25
|
-
that are not aligned to this Code of Conduct, or to ban temporarily or
|
26
|
-
permanently any contributor for other behaviors that they deem inappropriate,
|
27
|
-
threatening, offensive, or harmful.
|
28
|
-
|
29
|
-
By adopting this Code of Conduct, project maintainers commit themselves to
|
30
|
-
fairly and consistently applying these principles to every aspect of managing
|
31
|
-
this project. Project maintainers who do not follow or enforce the Code of
|
32
|
-
Conduct may be permanently removed from the project team.
|
33
|
-
|
34
|
-
This code of conduct applies both within project spaces and in public spaces
|
35
|
-
when an individual is representing the project or its community.
|
36
|
-
|
37
|
-
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
38
|
-
reported by contacting a project maintainer at vaughan.britton@sage.com. All
|
39
|
-
complaints will be reviewed and investigated and will result in a response that
|
40
|
-
is deemed necessary and appropriate to the circumstances. Maintainers are
|
41
|
-
obligated to maintain confidentiality with regard to the reporter of an
|
42
|
-
incident.
|
43
|
-
|
44
|
-
This Code of Conduct is adapted from the [Contributor Covenant][homepage],
|
45
|
-
version 1.3.0, available at
|
46
|
-
[http://contributor-covenant.org/version/1/3/0/][version]
|
47
|
-
|
48
|
-
[homepage]: http://contributor-covenant.org
|
49
|
-
[version]: http://contributor-covenant.org/version/1/3/0/
|
data/Gemfile
DELETED
data/Gemfile.lock
DELETED
@@ -1,43 +0,0 @@
|
|
1
|
-
PATH
|
2
|
-
remote: .
|
3
|
-
specs:
|
4
|
-
pwork (0.1.1)
|
5
|
-
|
6
|
-
GEM
|
7
|
-
remote: https://rubygems.org/
|
8
|
-
specs:
|
9
|
-
coderay (1.1.1)
|
10
|
-
diff-lcs (1.2.5)
|
11
|
-
method_source (0.8.2)
|
12
|
-
pry (0.10.3)
|
13
|
-
coderay (~> 1.1.0)
|
14
|
-
method_source (~> 0.8.1)
|
15
|
-
slop (~> 3.4)
|
16
|
-
rake (10.5.0)
|
17
|
-
rspec (3.4.0)
|
18
|
-
rspec-core (~> 3.4.0)
|
19
|
-
rspec-expectations (~> 3.4.0)
|
20
|
-
rspec-mocks (~> 3.4.0)
|
21
|
-
rspec-core (3.4.4)
|
22
|
-
rspec-support (~> 3.4.0)
|
23
|
-
rspec-expectations (3.4.0)
|
24
|
-
diff-lcs (>= 1.2.0, < 2.0)
|
25
|
-
rspec-support (~> 3.4.0)
|
26
|
-
rspec-mocks (3.4.1)
|
27
|
-
diff-lcs (>= 1.2.0, < 2.0)
|
28
|
-
rspec-support (~> 3.4.0)
|
29
|
-
rspec-support (3.4.1)
|
30
|
-
slop (3.6.0)
|
31
|
-
|
32
|
-
PLATFORMS
|
33
|
-
ruby
|
34
|
-
|
35
|
-
DEPENDENCIES
|
36
|
-
bundler (~> 1.11.2)
|
37
|
-
pry
|
38
|
-
pwork!
|
39
|
-
rake (~> 10.0)
|
40
|
-
rspec
|
41
|
-
|
42
|
-
BUNDLED WITH
|
43
|
-
1.11.2
|
data/LICENSE.txt
DELETED
@@ -1,21 +0,0 @@
|
|
1
|
-
The MIT License (MIT)
|
2
|
-
|
3
|
-
Copyright (c) 2016 vaughanbrittonsage
|
4
|
-
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
-
of this software and associated documentation files (the "Software"), to deal
|
7
|
-
in the Software without restriction, including without limitation the rights
|
8
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
-
copies of the Software, and to permit persons to whom the Software is
|
10
|
-
furnished to do so, subject to the following conditions:
|
11
|
-
|
12
|
-
The above copyright notice and this permission notice shall be included in
|
13
|
-
all copies or substantial portions of the Software.
|
14
|
-
|
15
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
-
THE SOFTWARE.
|
data/README.md
DELETED
@@ -1,95 +0,0 @@
|
|
1
|
-
# Pwork
|
2
|
-
|
3
|
-
Welcome to your Pwork. A gem to help with the execution of code on parallel threads.
|
4
|
-
|
5
|
-
> Parallel execution is especially useful at improving performance for long running I/O processes such as database & web service operations.
|
6
|
-
|
7
|
-
## Installation
|
8
|
-
|
9
|
-
Add this line to your application's Gemfile:
|
10
|
-
|
11
|
-
```ruby
|
12
|
-
gem 'pwork'
|
13
|
-
```
|
14
|
-
|
15
|
-
And then execute:
|
16
|
-
|
17
|
-
$ bundle
|
18
|
-
|
19
|
-
Or install it yourself as:
|
20
|
-
|
21
|
-
$ gem install pwork
|
22
|
-
|
23
|
-
## Usage
|
24
|
-
|
25
|
-
Pwork provides the following options for parallel work execution:
|
26
|
-
|
27
|
-
### #.peach
|
28
|
-
This method provides a parallel thread based execution of an each block iteration over an array.
|
29
|
-
|
30
|
-
**Params:**
|
31
|
-
|
32
|
-
- **thread_count** [Integer] [Optional] [Default=5] This is the number of threads that the parallel iteration should be spread across.
|
33
|
-
|
34
|
-
**Example:**
|
35
|
-
|
36
|
-
#array each iteration using the default thread count
|
37
|
-
array.peach do |item|
|
38
|
-
......
|
39
|
-
end
|
40
|
-
|
41
|
-
#array each iteration using a specified thread count
|
42
|
-
array.peach(8) do |item|
|
43
|
-
......
|
44
|
-
end
|
45
|
-
|
46
|
-
### Pwork::Worker
|
47
|
-
|
48
|
-
The worker object is used to attach one or more blocks of code to execute in parallel.
|
49
|
-
The number of threads to spread the parallel execution across can be specified in the workers construction.
|
50
|
-
|
51
|
-
**Params:**
|
52
|
-
|
53
|
-
- **thread_count** [Integer] [Optional] [Default=5] This is the number of threads that the parallel execution should be spread across.
|
54
|
-
|
55
|
-
**Example:**
|
56
|
-
|
57
|
-
#create a worker with the default number of parallel threads
|
58
|
-
worker = Pwork::Worker.new
|
59
|
-
|
60
|
-
#create a worker with a specific number of parallel threads
|
61
|
-
worker = Pwork::Worker.new(8)
|
62
|
-
|
63
|
-
Then add your blocks of code to execute in parallel:
|
64
|
-
|
65
|
-
worker.add do
|
66
|
-
.......
|
67
|
-
end
|
68
|
-
|
69
|
-
worker.add do
|
70
|
-
.......
|
71
|
-
end
|
72
|
-
|
73
|
-
Once all blocks of code required to be executed in parallel have been added to the worker, a call to the execute method is required to begin processing:
|
74
|
-
|
75
|
-
worker.execute
|
76
|
-
|
77
|
-
All blocks of code will be executed in parallel across the workers threads.
|
78
|
-
|
79
|
-
> The Worker object is not asynchronous, the worker processes are executed on separate threads in parallel but the worker execute method is synchronous and will wait until all execution has completed before continuing past the **worker.execute** call line.
|
80
|
-
|
81
|
-
## Development
|
82
|
-
|
83
|
-
After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
84
|
-
|
85
|
-
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
86
|
-
|
87
|
-
## Contributing
|
88
|
-
|
89
|
-
Bug reports and pull requests are welcome on GitHub at https://github.com/vaughanbrittonsage/pworker. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
|
90
|
-
|
91
|
-
|
92
|
-
## License
|
93
|
-
|
94
|
-
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
95
|
-
|
data/Rakefile
DELETED
data/bin/console
DELETED
@@ -1,14 +0,0 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
|
3
|
-
require "bundler/setup"
|
4
|
-
require "pwork"
|
5
|
-
|
6
|
-
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
-
# with your gem easier. You can also use a different console, if you like.
|
8
|
-
|
9
|
-
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
-
# require "pry"
|
11
|
-
# Pry.start
|
12
|
-
|
13
|
-
require "irb"
|
14
|
-
IRB.start
|
data/bin/setup
DELETED
data/lib/pwork.rb
DELETED
@@ -1,71 +0,0 @@
|
|
1
|
-
require "pwork/version"
|
2
|
-
|
3
|
-
module Pwork
|
4
|
-
|
5
|
-
class Worker
|
6
|
-
|
7
|
-
def initialize(thread_count = 5)
|
8
|
-
@processes = []
|
9
|
-
@thread_count = thread_count
|
10
|
-
end
|
11
|
-
|
12
|
-
#This method is called to add a process to this worker
|
13
|
-
def add(&block)
|
14
|
-
@processes.push(block)
|
15
|
-
end
|
16
|
-
|
17
|
-
#This method is called to execute all processes attached to this worker in parallel on the specified number of threads.
|
18
|
-
def execute
|
19
|
-
@processes.peach(@thread_count) do |item|
|
20
|
-
item.call
|
21
|
-
end
|
22
|
-
end
|
23
|
-
|
24
|
-
end
|
25
|
-
|
26
|
-
end
|
27
|
-
|
28
|
-
|
29
|
-
class Array
|
30
|
-
|
31
|
-
#This method is called to loop over each item in this array in parallel threads
|
32
|
-
def peach(thread_count = 5, &block)
|
33
|
-
@mutex = Mutex.new
|
34
|
-
@index_count = -1
|
35
|
-
threads = []
|
36
|
-
thread_count.times.each do
|
37
|
-
thread = Thread.new do
|
38
|
-
thread_process(&block)
|
39
|
-
end
|
40
|
-
threads.push(thread)
|
41
|
-
end
|
42
|
-
#wait for all threads to exit
|
43
|
-
threads.each { |thr| thr.join }
|
44
|
-
end
|
45
|
-
|
46
|
-
#This method is used to recursively process an item on a thread
|
47
|
-
def thread_process(&block)
|
48
|
-
|
49
|
-
item = nil
|
50
|
-
|
51
|
-
#use a mutex to get the next item from the array to ensure thread safety
|
52
|
-
@mutex.synchronize do
|
53
|
-
@index_count += 1
|
54
|
-
|
55
|
-
if @index_count <= self.length - 1
|
56
|
-
item = self[@index_count]
|
57
|
-
end
|
58
|
-
end
|
59
|
-
|
60
|
-
if item == nil
|
61
|
-
return
|
62
|
-
end
|
63
|
-
|
64
|
-
#execute the block for the current item
|
65
|
-
yield item
|
66
|
-
|
67
|
-
#recursively attempt to process another item from the array opn this thread
|
68
|
-
thread_process(&block)
|
69
|
-
end
|
70
|
-
|
71
|
-
end
|
data/lib/pwork/version.rb
DELETED
data/pwork.gemspec
DELETED
@@ -1,26 +0,0 @@
|
|
1
|
-
# coding: utf-8
|
2
|
-
lib = File.expand_path('../lib', __FILE__)
|
3
|
-
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
-
require 'pwork/version'
|
5
|
-
|
6
|
-
Gem::Specification.new do |spec|
|
7
|
-
spec.name = "pwork"
|
8
|
-
spec.version = Pwork::VERSION
|
9
|
-
spec.authors = ["vaughanbrittonage"]
|
10
|
-
spec.email = ["vaughanbritton@gmail.com"]
|
11
|
-
|
12
|
-
spec.summary = 'This is a library to facilitate with the execution of work on parallel threads.'
|
13
|
-
spec.description = 'This is a library to facilitate with the execution of work on parallel threads.'
|
14
|
-
spec.homepage = "https://github.com/vaughanbrittonsage/pwork"
|
15
|
-
spec.license = "MIT"
|
16
|
-
|
17
|
-
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
18
|
-
spec.bindir = "exe"
|
19
|
-
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
20
|
-
spec.require_paths = ["lib"]
|
21
|
-
|
22
|
-
spec.add_development_dependency "bundler", "~> 1.11.2"
|
23
|
-
spec.add_development_dependency "rake", "~> 10.0"
|
24
|
-
spec.add_development_dependency "rspec"
|
25
|
-
spec.add_development_dependency 'pry'
|
26
|
-
end
|