ractor_pool 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +11 -0
- data/.overcommit.yml +7 -0
- data/.rspec +4 -0
- data/.rubocop.yml +29 -0
- data/.travis.yml +6 -0
- data/CHANGELOG.md +0 -0
- data/CODE_OF_CONDUCT.md +74 -0
- data/Gemfile +9 -0
- data/Gemfile.lock +115 -0
- data/LICENSE.txt +21 -0
- data/README.md +44 -0
- data/Rakefile +8 -0
- data/bin/console +15 -0
- data/bin/setup +8 -0
- data/lib/ractor_pool.rb +23 -0
- data/lib/ractor_pool/channel.rb +46 -0
- data/lib/ractor_pool/mapper.rb +15 -0
- data/lib/ractor_pool/pool.rb +77 -0
- data/lib/ractor_pool/reducer.rb +14 -0
- data/lib/ractor_pool/reducers.rb +4 -0
- data/lib/ractor_pool/reducers/collect_reducer.rb +12 -0
- data/lib/ractor_pool/version.rb +5 -0
- data/lib/ractor_pool/worker.rb +13 -0
- data/ractor_pool.gemspec +35 -0
- metadata +182 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: f820ba82559eaaf7e44897051e349a686a2d62a72fda323d97bb38ff7c48b574
|
4
|
+
data.tar.gz: 583b3f3d1cae1ec926be061b774a4756180aceb94f80bc669b18dad735373e7d
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 73d0cd99f19df5d6e3361eb21282b24aab4e884c6acc327e07e412594c74fe2b79f703d1f537fe7f7c649e8bfde0acab3236093d469e2037005907cd574a7892
|
7
|
+
data.tar.gz: 9dccdc44842ce4afc6c262a9cb4f3741778bca19f1855fa521cbe4c90fa6f9b90951a07b04145a98a458cf4b890e3551a0ec5255de506d2b04192234b09f0cf3
|
data/.gitignore
ADDED
data/.overcommit.yml
ADDED
data/.rspec
ADDED
data/.rubocop.yml
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
require:
|
2
|
+
- rubocop-performance
|
3
|
+
- rubocop-rspec
|
4
|
+
- rubocop-rake
|
5
|
+
|
6
|
+
AllCops:
|
7
|
+
TargetRubyVersion: 3.0
|
8
|
+
NewCops: enable
|
9
|
+
|
10
|
+
Style/Documentation:
|
11
|
+
Enabled: false
|
12
|
+
|
13
|
+
Layout/LineLength:
|
14
|
+
Max: 120
|
15
|
+
Exclude:
|
16
|
+
- '**/*_spec.rb'
|
17
|
+
|
18
|
+
Metrics/BlockLength:
|
19
|
+
Exclude:
|
20
|
+
- '**/*_spec.rb'
|
21
|
+
|
22
|
+
Style/ClassAndModuleChildren:
|
23
|
+
EnforcedStyle: compact
|
24
|
+
|
25
|
+
RSpec/ExampleLength:
|
26
|
+
Enabled: false
|
27
|
+
|
28
|
+
Metrics/MethodLength:
|
29
|
+
Max: 15
|
data/.travis.yml
ADDED
data/CHANGELOG.md
ADDED
File without changes
|
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
# Contributor Covenant Code of Conduct
|
2
|
+
|
3
|
+
## Our Pledge
|
4
|
+
|
5
|
+
In the interest of fostering an open and welcoming environment, we as
|
6
|
+
contributors and maintainers pledge to making participation in our project and
|
7
|
+
our community a harassment-free experience for everyone, regardless of age, body
|
8
|
+
size, disability, ethnicity, gender identity and expression, level of experience,
|
9
|
+
nationality, personal appearance, race, religion, or sexual identity and
|
10
|
+
orientation.
|
11
|
+
|
12
|
+
## Our Standards
|
13
|
+
|
14
|
+
Examples of behavior that contributes to creating a positive environment
|
15
|
+
include:
|
16
|
+
|
17
|
+
* Using welcoming and inclusive language
|
18
|
+
* Being respectful of differing viewpoints and experiences
|
19
|
+
* Gracefully accepting constructive criticism
|
20
|
+
* Focusing on what is best for the community
|
21
|
+
* Showing empathy towards other community members
|
22
|
+
|
23
|
+
Examples of unacceptable behavior by participants include:
|
24
|
+
|
25
|
+
* The use of sexualized language or imagery and unwelcome sexual attention or
|
26
|
+
advances
|
27
|
+
* Trolling, insulting/derogatory comments, and personal or political attacks
|
28
|
+
* Public or private harassment
|
29
|
+
* Publishing others' private information, such as a physical or electronic
|
30
|
+
address, without explicit permission
|
31
|
+
* Other conduct which could reasonably be considered inappropriate in a
|
32
|
+
professional setting
|
33
|
+
|
34
|
+
## Our Responsibilities
|
35
|
+
|
36
|
+
Project maintainers are responsible for clarifying the standards of acceptable
|
37
|
+
behavior and are expected to take appropriate and fair corrective action in
|
38
|
+
response to any instances of unacceptable behavior.
|
39
|
+
|
40
|
+
Project maintainers have the right and responsibility to remove, edit, or
|
41
|
+
reject comments, commits, code, wiki edits, issues, and other contributions
|
42
|
+
that are not aligned to this Code of Conduct, or to ban temporarily or
|
43
|
+
permanently any contributor for other behaviors that they deem inappropriate,
|
44
|
+
threatening, offensive, or harmful.
|
45
|
+
|
46
|
+
## Scope
|
47
|
+
|
48
|
+
This Code of Conduct applies both within project spaces and in public spaces
|
49
|
+
when an individual is representing the project or its community. Examples of
|
50
|
+
representing a project or community include using an official project e-mail
|
51
|
+
address, posting via an official social media account, or acting as an appointed
|
52
|
+
representative at an online or offline event. Representation of a project may be
|
53
|
+
further defined and clarified by project maintainers.
|
54
|
+
|
55
|
+
## Enforcement
|
56
|
+
|
57
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
58
|
+
reported by contacting the project team at zhulik.gleb@gmail.com. All
|
59
|
+
complaints will be reviewed and investigated and will result in a response that
|
60
|
+
is deemed necessary and appropriate to the circumstances. The project team is
|
61
|
+
obligated to maintain confidentiality with regard to the reporter of an incident.
|
62
|
+
Further details of specific enforcement policies may be posted separately.
|
63
|
+
|
64
|
+
Project maintainers who do not follow or enforce the Code of Conduct in good
|
65
|
+
faith may face temporary or permanent repercussions as determined by other
|
66
|
+
members of the project's leadership.
|
67
|
+
|
68
|
+
## Attribution
|
69
|
+
|
70
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
|
71
|
+
available at [https://contributor-covenant.org/version/1/4][version]
|
72
|
+
|
73
|
+
[homepage]: https://contributor-covenant.org
|
74
|
+
[version]: https://contributor-covenant.org/version/1/4/
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,115 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
ractor_pool (0.1.0)
|
5
|
+
|
6
|
+
GEM
|
7
|
+
remote: https://rubygems.org/
|
8
|
+
specs:
|
9
|
+
ast (2.4.2)
|
10
|
+
backport (1.1.2)
|
11
|
+
benchmark (0.1.1)
|
12
|
+
childprocess (4.0.0)
|
13
|
+
diff-lcs (1.4.4)
|
14
|
+
docile (1.3.5)
|
15
|
+
e2mmap (0.1.0)
|
16
|
+
iniparse (1.5.0)
|
17
|
+
jaro_winkler (1.5.4)
|
18
|
+
kramdown (2.3.1)
|
19
|
+
rexml
|
20
|
+
kramdown-parser-gfm (1.1.0)
|
21
|
+
kramdown (~> 2.0)
|
22
|
+
mini_portile2 (2.5.0)
|
23
|
+
nokogiri (1.11.2)
|
24
|
+
mini_portile2 (~> 2.5.0)
|
25
|
+
racc (~> 1.4)
|
26
|
+
overcommit (0.57.0)
|
27
|
+
childprocess (>= 0.6.3, < 5)
|
28
|
+
iniparse (~> 1.4)
|
29
|
+
parallel (1.20.1)
|
30
|
+
parser (3.0.0.0)
|
31
|
+
ast (~> 2.4.1)
|
32
|
+
racc (1.5.2)
|
33
|
+
rainbow (3.0.0)
|
34
|
+
rake (12.3.3)
|
35
|
+
regexp_parser (2.1.1)
|
36
|
+
reverse_markdown (2.0.0)
|
37
|
+
nokogiri
|
38
|
+
rexml (3.2.4)
|
39
|
+
rspec (3.10.0)
|
40
|
+
rspec-core (~> 3.10.0)
|
41
|
+
rspec-expectations (~> 3.10.0)
|
42
|
+
rspec-mocks (~> 3.10.0)
|
43
|
+
rspec-core (3.10.0)
|
44
|
+
rspec-support (~> 3.10.0)
|
45
|
+
rspec-expectations (3.10.0)
|
46
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
47
|
+
rspec-support (~> 3.10.0)
|
48
|
+
rspec-mocks (3.10.0)
|
49
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
50
|
+
rspec-support (~> 3.10.0)
|
51
|
+
rspec-support (3.10.0)
|
52
|
+
rubocop (1.12.0)
|
53
|
+
parallel (~> 1.10)
|
54
|
+
parser (>= 3.0.0.0)
|
55
|
+
rainbow (>= 2.2.2, < 4.0)
|
56
|
+
regexp_parser (>= 1.8, < 3.0)
|
57
|
+
rexml
|
58
|
+
rubocop-ast (>= 1.2.0, < 2.0)
|
59
|
+
ruby-progressbar (~> 1.7)
|
60
|
+
unicode-display_width (>= 1.4.0, < 3.0)
|
61
|
+
rubocop-ast (1.4.1)
|
62
|
+
parser (>= 2.7.1.5)
|
63
|
+
rubocop-performance (1.10.2)
|
64
|
+
rubocop (>= 0.90.0, < 2.0)
|
65
|
+
rubocop-ast (>= 0.4.0)
|
66
|
+
rubocop-rake (0.5.1)
|
67
|
+
rubocop
|
68
|
+
rubocop-rspec (2.2.0)
|
69
|
+
rubocop (~> 1.0)
|
70
|
+
rubocop-ast (>= 1.1.0)
|
71
|
+
ruby-progressbar (1.11.0)
|
72
|
+
simplecov (0.21.2)
|
73
|
+
docile (~> 1.1)
|
74
|
+
simplecov-html (~> 0.11)
|
75
|
+
simplecov_json_formatter (~> 0.1)
|
76
|
+
simplecov-html (0.12.3)
|
77
|
+
simplecov_json_formatter (0.1.2)
|
78
|
+
solargraph (0.40.4)
|
79
|
+
backport (~> 1.1)
|
80
|
+
benchmark
|
81
|
+
bundler (>= 1.17.2)
|
82
|
+
e2mmap
|
83
|
+
jaro_winkler (~> 1.5)
|
84
|
+
kramdown (~> 2.3)
|
85
|
+
kramdown-parser-gfm (~> 1.1)
|
86
|
+
parser (~> 3.0)
|
87
|
+
reverse_markdown (>= 1.0.5, < 3)
|
88
|
+
rubocop (>= 0.52)
|
89
|
+
thor (~> 1.0)
|
90
|
+
tilt (~> 2.0)
|
91
|
+
yard (~> 0.9, >= 0.9.24)
|
92
|
+
thor (1.1.0)
|
93
|
+
tilt (2.0.10)
|
94
|
+
unicode-display_width (2.0.0)
|
95
|
+
yard (0.9.26)
|
96
|
+
zeitwerk (2.4.2)
|
97
|
+
|
98
|
+
PLATFORMS
|
99
|
+
ruby
|
100
|
+
|
101
|
+
DEPENDENCIES
|
102
|
+
overcommit (~> 0.57)
|
103
|
+
ractor_pool!
|
104
|
+
rake (~> 12.0)
|
105
|
+
rspec (~> 3.0)
|
106
|
+
rubocop (~> 1.12)
|
107
|
+
rubocop-performance (~> 1.10)
|
108
|
+
rubocop-rake (~> 0.5)
|
109
|
+
rubocop-rspec (~> 2.2)
|
110
|
+
simplecov (~> 0.21)
|
111
|
+
solargraph (~> 0.40)
|
112
|
+
zeitwerk (~> 2.4)
|
113
|
+
|
114
|
+
BUNDLED WITH
|
115
|
+
2.2.3
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2021 Gleb Sinyavskiy
|
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
ADDED
@@ -0,0 +1,44 @@
|
|
1
|
+
# RactorPool
|
2
|
+
|
3
|
+
Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/ractor_pool`. To experiment with that code, run `bin/console` for an interactive prompt.
|
4
|
+
|
5
|
+
TODO: Delete this and the text above, and describe your gem
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
Add this line to your application's Gemfile:
|
10
|
+
|
11
|
+
```ruby
|
12
|
+
gem 'ractor_pool'
|
13
|
+
```
|
14
|
+
|
15
|
+
And then execute:
|
16
|
+
|
17
|
+
$ bundle install
|
18
|
+
|
19
|
+
Or install it yourself as:
|
20
|
+
|
21
|
+
$ gem install ractor_pool
|
22
|
+
|
23
|
+
## Usage
|
24
|
+
|
25
|
+
TODO: Write usage instructions here
|
26
|
+
|
27
|
+
## Development
|
28
|
+
|
29
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
30
|
+
|
31
|
+
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).
|
32
|
+
|
33
|
+
## Contributing
|
34
|
+
|
35
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/ractor_pool. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/[USERNAME]/ractor_pool/blob/master/CODE_OF_CONDUCT.md).
|
36
|
+
|
37
|
+
|
38
|
+
## License
|
39
|
+
|
40
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
41
|
+
|
42
|
+
## Code of Conduct
|
43
|
+
|
44
|
+
Everyone interacting in the RactorPool project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/ractor_pool/blob/master/CODE_OF_CONDUCT.md).
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
require 'bundler/setup'
|
5
|
+
require 'ractor_pool'
|
6
|
+
|
7
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
8
|
+
# with your gem easier. You can also use a different console, if you like.
|
9
|
+
|
10
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
11
|
+
# require "pry"
|
12
|
+
# Pry.start
|
13
|
+
|
14
|
+
require 'irb'
|
15
|
+
IRB.start(__FILE__)
|
data/bin/setup
ADDED
data/lib/ractor_pool.rb
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'rubygems'
|
4
|
+
require 'bundler/setup'
|
5
|
+
|
6
|
+
require 'zeitwerk'
|
7
|
+
|
8
|
+
loader = Zeitwerk::Loader.for_gem
|
9
|
+
|
10
|
+
loader.setup
|
11
|
+
|
12
|
+
require 'logger'
|
13
|
+
|
14
|
+
class RactorPool::Error < StandardError
|
15
|
+
end
|
16
|
+
|
17
|
+
module RactorPool
|
18
|
+
class << self
|
19
|
+
def new(mapper_class:, jobs: Etc.nprocessors)
|
20
|
+
Pool.new(jobs: jobs, mapper_class: mapper_class)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,46 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
class RactorPool::Channel
|
4
|
+
def initialize # rubocop:disable Metrics/MethodLength
|
5
|
+
@pipe = Ractor.new do
|
6
|
+
listeners_count = 0
|
7
|
+
loop do
|
8
|
+
msg = Ractor.recv
|
9
|
+
case msg
|
10
|
+
in type: :close
|
11
|
+
listeners_count.times { Ractor.yield(msg) }
|
12
|
+
break
|
13
|
+
in type: :subscription
|
14
|
+
listeners_count += 1
|
15
|
+
Ractor.yield({ type: :skip })
|
16
|
+
in type: :data
|
17
|
+
Ractor.yield({ type: :data, data: msg[:data] })
|
18
|
+
else
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
def <<(data)
|
25
|
+
@pipe.send({ type: :data, data: data })
|
26
|
+
end
|
27
|
+
|
28
|
+
def close!
|
29
|
+
@pipe.send({ type: :close }, move: true)
|
30
|
+
end
|
31
|
+
|
32
|
+
def subscribe
|
33
|
+
@pipe.send({ type: :subscription }, move: true)
|
34
|
+
loop do
|
35
|
+
msg = @pipe.take
|
36
|
+
case msg
|
37
|
+
in type: :close
|
38
|
+
return
|
39
|
+
in type: :data
|
40
|
+
yield(msg[:data])
|
41
|
+
else
|
42
|
+
end
|
43
|
+
end
|
44
|
+
rescue Ractor::ClosedError # rubocop:disable Lint/SuppressedException
|
45
|
+
end
|
46
|
+
end
|
@@ -0,0 +1,77 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
class RactorPool::Pool
|
4
|
+
def initialize(jobs:, mapper_class:, reducer_class: RactorPool::Reducers::CollectReducer)
|
5
|
+
@jobs = jobs
|
6
|
+
@logger = Logger.new($stdout)
|
7
|
+
@mapper_class = mapper_class
|
8
|
+
@reducer_class = reducer_class
|
9
|
+
end
|
10
|
+
|
11
|
+
def start
|
12
|
+
reducer
|
13
|
+
workers
|
14
|
+
self
|
15
|
+
end
|
16
|
+
|
17
|
+
def schedule(*args, **params)
|
18
|
+
jobs_pipe << { type: :job, args: args, params: params }
|
19
|
+
self
|
20
|
+
end
|
21
|
+
|
22
|
+
def stop
|
23
|
+
jobs_pipe.close!
|
24
|
+
workers.each(&:take)
|
25
|
+
results_pipe.close!
|
26
|
+
result = reducer.take
|
27
|
+
instance_variable_set(:@jobs_pipe, nil)
|
28
|
+
instance_variable_set(:@resuts_pipe, nil)
|
29
|
+
instance_variable_set(:@workers, nil)
|
30
|
+
instance_variable_set(:@reducer, nil)
|
31
|
+
result
|
32
|
+
end
|
33
|
+
|
34
|
+
private
|
35
|
+
|
36
|
+
def jobs_pipe
|
37
|
+
@jobs_pipe ||= RactorPool::Channel.new
|
38
|
+
end
|
39
|
+
|
40
|
+
def results_pipe
|
41
|
+
@results_pipe ||= RactorPool::Channel.new
|
42
|
+
end
|
43
|
+
|
44
|
+
def workers # rubocop:disable Metrics/MethodLength
|
45
|
+
@workers ||= (1..@jobs).map do |worker_id|
|
46
|
+
Ractor.new(worker_id, jobs_pipe, results_pipe, @mapper_class,
|
47
|
+
@logger) do |worker_id, jobs_pipe, results_pipe, mapper_class, logger|
|
48
|
+
logger.debug("Worker #{worker_id}: started")
|
49
|
+
jobs_pipe.subscribe do |data|
|
50
|
+
logger.debug("Worker #{worker_id}: received data: #{data}")
|
51
|
+
case data
|
52
|
+
in args: args, params: params
|
53
|
+
logger.debug("Worker #{worker_id}: running #{mapper_class}.call(*#{args}, **#{params}))")
|
54
|
+
results_pipe << { type: :result, worker_id: worker_id, args: args, params: params,
|
55
|
+
result: mapper_class.call(logger, *args, **params) }
|
56
|
+
else
|
57
|
+
logger.debug("Worker #{worker_id}: Unknown data received: #{msg}")
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
def reducer
|
65
|
+
@reducer ||= Ractor.new(results_pipe, @logger, @reducer_class) do |results_pipe, logger, reducer_class|
|
66
|
+
logger.debug('Reducer: started')
|
67
|
+
|
68
|
+
reducer = reducer_class.new(logger: logger)
|
69
|
+
result = nil
|
70
|
+
results_pipe.subscribe do |data|
|
71
|
+
logger.debug("Reducer: received data: #{data}")
|
72
|
+
result = reducer.call(**data)
|
73
|
+
end
|
74
|
+
Ractor.yield(result)
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
class RactorPool::Worker
|
4
|
+
def initialize(*args)
|
5
|
+
Ractor.new(args) do |worker_id, jobs_pipe, _results_pipe, logger|
|
6
|
+
# logger = Logger.new($stdout)
|
7
|
+
jobs_pipe.subscribe do |data|
|
8
|
+
logger.debug("Worker #{worker_id}: received data: #{data}")
|
9
|
+
yield(data, logger)
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
data/ractor_pool.gemspec
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative 'lib/ractor_pool/version'
|
4
|
+
|
5
|
+
Gem::Specification.new do |spec|
|
6
|
+
spec.name = 'ractor_pool'
|
7
|
+
spec.version = RactorPool::VERSION
|
8
|
+
spec.authors = ['Gleb Sinyavskiy']
|
9
|
+
spec.email = ['zhulik.gleb@gmail.com']
|
10
|
+
|
11
|
+
spec.summary = 'A worker pool based on ractor.'
|
12
|
+
spec.description = 'A worker pool based on ractor.'
|
13
|
+
spec.homepage = 'https://github.com/zhulik/ractor_pool'
|
14
|
+
spec.license = 'MIT'
|
15
|
+
spec.required_ruby_version = Gem::Requirement.new('>= 3.0.0')
|
16
|
+
|
17
|
+
spec.metadata['homepage_uri'] = spec.homepage
|
18
|
+
spec.metadata['source_code_uri'] = 'https://github.com/zhulik/ractor_pool'
|
19
|
+
spec.metadata['changelog_uri'] = 'https://github.com/zhulik/ractor_pool/blob/main/CHANGELOG.md'
|
20
|
+
|
21
|
+
spec.files = Dir.chdir(File.expand_path(__dir__)) do
|
22
|
+
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
23
|
+
end
|
24
|
+
spec.require_paths = ['lib']
|
25
|
+
|
26
|
+
spec.add_development_dependency 'zeitwerk', '~>2.4'
|
27
|
+
|
28
|
+
spec.add_development_dependency 'overcommit', '~>0.57'
|
29
|
+
spec.add_development_dependency 'rubocop', '~>1.12'
|
30
|
+
spec.add_development_dependency 'rubocop-performance', '~>1.10'
|
31
|
+
spec.add_development_dependency 'rubocop-rake', '~>0.5'
|
32
|
+
spec.add_development_dependency 'rubocop-rspec', '~>2.2'
|
33
|
+
spec.add_development_dependency 'simplecov', '~>0.21'
|
34
|
+
spec.add_development_dependency 'solargraph', '~>0.40'
|
35
|
+
end
|
metadata
ADDED
@@ -0,0 +1,182 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: ractor_pool
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Gleb Sinyavskiy
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2021-04-03 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: zeitwerk
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '2.4'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '2.4'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: overcommit
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0.57'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0.57'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rubocop
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '1.12'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '1.12'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rubocop-performance
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '1.10'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '1.10'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rubocop-rake
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0.5'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0.5'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: rubocop-rspec
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - "~>"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '2.2'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - "~>"
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '2.2'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: simplecov
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - "~>"
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0.21'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - "~>"
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0.21'
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: solargraph
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - "~>"
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '0.40'
|
118
|
+
type: :development
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - "~>"
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: '0.40'
|
125
|
+
description: A worker pool based on ractor.
|
126
|
+
email:
|
127
|
+
- zhulik.gleb@gmail.com
|
128
|
+
executables: []
|
129
|
+
extensions: []
|
130
|
+
extra_rdoc_files: []
|
131
|
+
files:
|
132
|
+
- ".gitignore"
|
133
|
+
- ".overcommit.yml"
|
134
|
+
- ".rspec"
|
135
|
+
- ".rubocop.yml"
|
136
|
+
- ".travis.yml"
|
137
|
+
- CHANGELOG.md
|
138
|
+
- CODE_OF_CONDUCT.md
|
139
|
+
- Gemfile
|
140
|
+
- Gemfile.lock
|
141
|
+
- LICENSE.txt
|
142
|
+
- README.md
|
143
|
+
- Rakefile
|
144
|
+
- bin/console
|
145
|
+
- bin/setup
|
146
|
+
- lib/ractor_pool.rb
|
147
|
+
- lib/ractor_pool/channel.rb
|
148
|
+
- lib/ractor_pool/mapper.rb
|
149
|
+
- lib/ractor_pool/pool.rb
|
150
|
+
- lib/ractor_pool/reducer.rb
|
151
|
+
- lib/ractor_pool/reducers.rb
|
152
|
+
- lib/ractor_pool/reducers/collect_reducer.rb
|
153
|
+
- lib/ractor_pool/version.rb
|
154
|
+
- lib/ractor_pool/worker.rb
|
155
|
+
- ractor_pool.gemspec
|
156
|
+
homepage: https://github.com/zhulik/ractor_pool
|
157
|
+
licenses:
|
158
|
+
- MIT
|
159
|
+
metadata:
|
160
|
+
homepage_uri: https://github.com/zhulik/ractor_pool
|
161
|
+
source_code_uri: https://github.com/zhulik/ractor_pool
|
162
|
+
changelog_uri: https://github.com/zhulik/ractor_pool/blob/main/CHANGELOG.md
|
163
|
+
post_install_message:
|
164
|
+
rdoc_options: []
|
165
|
+
require_paths:
|
166
|
+
- lib
|
167
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
168
|
+
requirements:
|
169
|
+
- - ">="
|
170
|
+
- !ruby/object:Gem::Version
|
171
|
+
version: 3.0.0
|
172
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
173
|
+
requirements:
|
174
|
+
- - ">="
|
175
|
+
- !ruby/object:Gem::Version
|
176
|
+
version: '0'
|
177
|
+
requirements: []
|
178
|
+
rubygems_version: 3.2.3
|
179
|
+
signing_key:
|
180
|
+
specification_version: 4
|
181
|
+
summary: A worker pool based on ractor.
|
182
|
+
test_files: []
|