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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: e211f06213c82dc2719245bd2864d1c078673518
4
- data.tar.gz: 8851cd0e4e76fcfb68650361532f6da630fff5dc
3
+ metadata.gz: 15f4c4a2ca14320dff30454942391f11899747b3
4
+ data.tar.gz: 6e7236ea011bcf47d87cf46d6c89e8ede2155bb8
5
5
  SHA512:
6
- metadata.gz: beffa0245050025c639207ca9a0b9124ae70fbb6ba1c4290e80ee92a309d93c27db4f793bbcff160e6d14418ae1d34bd5943f5dfe89681299292ecdffa1311f6
7
- data.tar.gz: 63b0f7feca632604e96239f6a380e8063dbb35939155d232535a9e0a5d7f94af5948701e78a558a9cb798782e58b713e6883295696a5e3aee3c02c84463f4777
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.1.1
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: 2016-05-26 00:00:00.000000000 Z
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: 1.11.2
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: 1.11.2
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
@@ -1,2 +0,0 @@
1
- ---
2
- BUNDLE_WITHOUT: uat:staging:preprod:production
data/.gitignore DELETED
@@ -1,5 +0,0 @@
1
- src/.DS_Store
2
- .DS_Store
3
- src/log/*
4
- src/tmp/*
5
- .idea
data/.rspec DELETED
@@ -1,3 +0,0 @@
1
- --color
2
- --require spec_helper
3
- --format doc
@@ -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
@@ -1,4 +0,0 @@
1
- source 'https://rubygems.org'
2
-
3
- # Specify your gem's dependencies in pworker.gemspec
4
- gemspec
@@ -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
@@ -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
@@ -1,2 +0,0 @@
1
- require "bundler/gem_tasks"
2
- task :default => :spec
@@ -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
@@ -1,8 +0,0 @@
1
- #!/usr/bin/env bash
2
- set -euo pipefail
3
- IFS=$'\n\t'
4
- set -vx
5
-
6
- bundle install
7
-
8
- # Do any other automated setup that you need to do here
@@ -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
@@ -1,3 +0,0 @@
1
- module Pwork
2
- VERSION = "0.1.1"
3
- end
@@ -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