async-container 0.16.5 → 0.16.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/async/container/generic.rb +13 -4
- data/lib/async/container/notify/pipe.rb +0 -16
- data/lib/async/container/version.rb +1 -1
- metadata +30 -73
- data/.editorconfig +0 -6
- data/.github/workflows/development.yml +0 -36
- data/.gitignore +0 -21
- data/.rspec +0 -3
- data/.yardopts +0 -1
- data/Gemfile +0 -19
- data/Guardfile +0 -14
- data/README.md +0 -140
- data/async-container.gemspec +0 -34
- data/examples/async.rb +0 -22
- data/examples/channel.rb +0 -45
- data/examples/channels/client.rb +0 -103
- data/examples/container.rb +0 -33
- data/examples/isolate.rb +0 -36
- data/examples/minimal.rb +0 -94
- data/examples/test.rb +0 -51
- data/examples/threads.rb +0 -25
- data/examples/title.rb +0 -13
- data/examples/udppipe.rb +0 -35
- data/spec/async/container/controller_spec.rb +0 -148
- data/spec/async/container/dots.rb +0 -29
- data/spec/async/container/forked_spec.rb +0 -61
- data/spec/async/container/hybrid_spec.rb +0 -36
- data/spec/async/container/notify/notify.rb +0 -19
- data/spec/async/container/notify/pipe_spec.rb +0 -48
- data/spec/async/container/notify_spec.rb +0 -56
- data/spec/async/container/shared_examples.rb +0 -80
- data/spec/async/container/threaded_spec.rb +0 -35
- data/spec/async/container_spec.rb +0 -41
- data/spec/spec_helper.rb +0 -21
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: cffebcdeda8a463f4bd854a2023b6942dfd56f7c0d4985555c5b2fc8ef6b5f93
|
4
|
+
data.tar.gz: a39ea00fceed362028c189a687372d0214b2c1da0b7b88aa16cbd4375d19b75a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b3939f550483a2330876833d50b9e79e604e81ca42160190d15b6bfb9ac213a3b4ee8851fb0f079402ffb32e5c14b29563d6beedc4cdec337d975af2bec15fc9
|
7
|
+
data.tar.gz: 9afebedefb06016327f5f3c88a134dc825cfbd52d1206822d8a430cc7498a6e5a90ebb4996b7157e9388f0c089c2b8135e98f188a57ef71029de190d79b05fa1
|
@@ -30,11 +30,20 @@ require_relative 'statistics'
|
|
30
30
|
|
31
31
|
module Async
|
32
32
|
module Container
|
33
|
+
ASYNC_CONTAINER_PROCESSOR_COUNT = 'ASYNC_CONTAINER_PROCESSOR_COUNT'
|
34
|
+
|
35
|
+
# The processor count which may be used for the default number of container threads/processes. You can override the value provided by the system by specifying the ASYNC_CONTAINER_PROCESSOR_COUNT environment variable.
|
33
36
|
# @return [Integer] the number of hardware processors which can run threads/processes simultaneously.
|
34
|
-
def self.processor_count
|
35
|
-
|
36
|
-
|
37
|
-
|
37
|
+
def self.processor_count(env = ENV)
|
38
|
+
count = env.fetch(ASYNC_CONTAINER_PROCESSOR_COUNT) do
|
39
|
+
Etc.nprocessors rescue 1
|
40
|
+
end.to_i
|
41
|
+
|
42
|
+
if count < 1
|
43
|
+
raise RuntimeError, "Invalid processor count #{count}!"
|
44
|
+
end
|
45
|
+
|
46
|
+
return count
|
38
47
|
end
|
39
48
|
|
40
49
|
class Generic
|
@@ -83,22 +83,6 @@ module Async
|
|
83
83
|
send(ready: true, **message)
|
84
84
|
end
|
85
85
|
|
86
|
-
def restarting!(**message)
|
87
|
-
message[:ready] = false
|
88
|
-
message[:reloading] = true
|
89
|
-
message[:status] ||= "Restarting..."
|
90
|
-
|
91
|
-
send(**message)
|
92
|
-
end
|
93
|
-
|
94
|
-
def reloading!(**message)
|
95
|
-
message[:ready] = false
|
96
|
-
message[:reloading] = true
|
97
|
-
message[:status] ||= "Reloading..."
|
98
|
-
|
99
|
-
send(**message)
|
100
|
-
end
|
101
|
-
|
102
86
|
private
|
103
87
|
|
104
88
|
def environment_for(arguments)
|
metadata
CHANGED
@@ -1,29 +1,15 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: async-container
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.16.
|
4
|
+
version: 0.16.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Samuel Williams
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-
|
11
|
+
date: 2020-06-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
|
-
- !ruby/object:Gem::Dependency
|
14
|
-
name: process-group
|
15
|
-
requirement: !ruby/object:Gem::Requirement
|
16
|
-
requirements:
|
17
|
-
- - ">="
|
18
|
-
- !ruby/object:Gem::Version
|
19
|
-
version: '0'
|
20
|
-
type: :runtime
|
21
|
-
prerelease: false
|
22
|
-
version_requirements: !ruby/object:Gem::Requirement
|
23
|
-
requirements:
|
24
|
-
- - ">="
|
25
|
-
- !ruby/object:Gem::Version
|
26
|
-
version: '0'
|
27
13
|
- !ruby/object:Gem::Dependency
|
28
14
|
name: async
|
29
15
|
requirement: !ruby/object:Gem::Requirement
|
@@ -67,7 +53,7 @@ dependencies:
|
|
67
53
|
- !ruby/object:Gem::Version
|
68
54
|
version: '1.1'
|
69
55
|
- !ruby/object:Gem::Dependency
|
70
|
-
name:
|
56
|
+
name: bake-bundler
|
71
57
|
requirement: !ruby/object:Gem::Requirement
|
72
58
|
requirements:
|
73
59
|
- - ">="
|
@@ -81,7 +67,7 @@ dependencies:
|
|
81
67
|
- !ruby/object:Gem::Version
|
82
68
|
version: '0'
|
83
69
|
- !ruby/object:Gem::Dependency
|
84
|
-
name:
|
70
|
+
name: bake-modernize
|
85
71
|
requirement: !ruby/object:Gem::Requirement
|
86
72
|
requirements:
|
87
73
|
- - ">="
|
@@ -95,21 +81,21 @@ dependencies:
|
|
95
81
|
- !ruby/object:Gem::Version
|
96
82
|
version: '0'
|
97
83
|
- !ruby/object:Gem::Dependency
|
98
|
-
name:
|
84
|
+
name: bundler
|
99
85
|
requirement: !ruby/object:Gem::Requirement
|
100
86
|
requirements:
|
101
|
-
- - "
|
87
|
+
- - ">="
|
102
88
|
- !ruby/object:Gem::Version
|
103
|
-
version: '
|
89
|
+
version: '0'
|
104
90
|
type: :development
|
105
91
|
prerelease: false
|
106
92
|
version_requirements: !ruby/object:Gem::Requirement
|
107
93
|
requirements:
|
108
|
-
- - "
|
94
|
+
- - ">="
|
109
95
|
- !ruby/object:Gem::Version
|
110
|
-
version: '
|
96
|
+
version: '0'
|
111
97
|
- !ruby/object:Gem::Dependency
|
112
|
-
name:
|
98
|
+
name: covered
|
113
99
|
requirement: !ruby/object:Gem::Requirement
|
114
100
|
requirements:
|
115
101
|
- - ">="
|
@@ -122,33 +108,26 @@ dependencies:
|
|
122
108
|
- - ">="
|
123
109
|
- !ruby/object:Gem::Version
|
124
110
|
version: '0'
|
125
|
-
|
126
|
-
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: rspec
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - "~>"
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '3.6'
|
118
|
+
type: :development
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - "~>"
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: '3.6'
|
125
|
+
description:
|
127
126
|
email:
|
128
|
-
- samuel.williams@oriontransfer.co.nz
|
129
127
|
executables: []
|
130
128
|
extensions: []
|
131
129
|
extra_rdoc_files: []
|
132
130
|
files:
|
133
|
-
- ".editorconfig"
|
134
|
-
- ".github/workflows/development.yml"
|
135
|
-
- ".gitignore"
|
136
|
-
- ".rspec"
|
137
|
-
- ".yardopts"
|
138
|
-
- Gemfile
|
139
|
-
- Guardfile
|
140
|
-
- README.md
|
141
|
-
- async-container.gemspec
|
142
|
-
- examples/async.rb
|
143
|
-
- examples/channel.rb
|
144
|
-
- examples/channels/client.rb
|
145
|
-
- examples/container.rb
|
146
|
-
- examples/isolate.rb
|
147
|
-
- examples/minimal.rb
|
148
|
-
- examples/test.rb
|
149
|
-
- examples/threads.rb
|
150
|
-
- examples/title.rb
|
151
|
-
- examples/udppipe.rb
|
152
131
|
- lib/async/container.rb
|
153
132
|
- lib/async/container/best.rb
|
154
133
|
- lib/async/container/channel.rb
|
@@ -170,22 +149,11 @@ files:
|
|
170
149
|
- lib/async/container/thread.rb
|
171
150
|
- lib/async/container/threaded.rb
|
172
151
|
- lib/async/container/version.rb
|
173
|
-
- spec/async/container/controller_spec.rb
|
174
|
-
- spec/async/container/dots.rb
|
175
|
-
- spec/async/container/forked_spec.rb
|
176
|
-
- spec/async/container/hybrid_spec.rb
|
177
|
-
- spec/async/container/notify/notify.rb
|
178
|
-
- spec/async/container/notify/pipe_spec.rb
|
179
|
-
- spec/async/container/notify_spec.rb
|
180
|
-
- spec/async/container/shared_examples.rb
|
181
|
-
- spec/async/container/threaded_spec.rb
|
182
|
-
- spec/async/container_spec.rb
|
183
|
-
- spec/spec_helper.rb
|
184
152
|
homepage: https://github.com/socketry/async-container
|
185
153
|
licenses:
|
186
154
|
- MIT
|
187
155
|
metadata: {}
|
188
|
-
post_install_message:
|
156
|
+
post_install_message:
|
189
157
|
rdoc_options: []
|
190
158
|
require_paths:
|
191
159
|
- lib
|
@@ -201,18 +169,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
201
169
|
version: '0'
|
202
170
|
requirements: []
|
203
171
|
rubygems_version: 3.1.2
|
204
|
-
signing_key:
|
172
|
+
signing_key:
|
205
173
|
specification_version: 4
|
206
|
-
summary:
|
207
|
-
test_files:
|
208
|
-
- spec/async/container/controller_spec.rb
|
209
|
-
- spec/async/container/dots.rb
|
210
|
-
- spec/async/container/forked_spec.rb
|
211
|
-
- spec/async/container/hybrid_spec.rb
|
212
|
-
- spec/async/container/notify/notify.rb
|
213
|
-
- spec/async/container/notify/pipe_spec.rb
|
214
|
-
- spec/async/container/notify_spec.rb
|
215
|
-
- spec/async/container/shared_examples.rb
|
216
|
-
- spec/async/container/threaded_spec.rb
|
217
|
-
- spec/async/container_spec.rb
|
218
|
-
- spec/spec_helper.rb
|
174
|
+
summary: Abstract container-based parallelism using threads and processes where appropriate.
|
175
|
+
test_files: []
|
data/.editorconfig
DELETED
@@ -1,36 +0,0 @@
|
|
1
|
-
name: Development
|
2
|
-
|
3
|
-
on: [push]
|
4
|
-
|
5
|
-
jobs:
|
6
|
-
test:
|
7
|
-
strategy:
|
8
|
-
matrix:
|
9
|
-
os:
|
10
|
-
- ubuntu
|
11
|
-
- macos
|
12
|
-
|
13
|
-
ruby:
|
14
|
-
- 2.5
|
15
|
-
- 2.6
|
16
|
-
- 2.7
|
17
|
-
- jruby
|
18
|
-
|
19
|
-
include:
|
20
|
-
- os: 'ubuntu'
|
21
|
-
ruby: '2.6'
|
22
|
-
env: COVERAGE=PartialSummary,Coveralls
|
23
|
-
|
24
|
-
runs-on: ${{matrix.os}}-latest
|
25
|
-
|
26
|
-
steps:
|
27
|
-
- uses: actions/checkout@v1
|
28
|
-
- uses: ruby/setup-ruby@v1
|
29
|
-
with:
|
30
|
-
ruby-version: ${{matrix.ruby}}
|
31
|
-
- name: Install dependencies
|
32
|
-
run: |
|
33
|
-
command -v bundler || gem install bundler
|
34
|
-
bundle install
|
35
|
-
- name: Run tests
|
36
|
-
run: ${{matrix.env}} bundle exec rspec
|
data/.gitignore
DELETED
@@ -1,21 +0,0 @@
|
|
1
|
-
*.gem
|
2
|
-
*.rbc
|
3
|
-
.bundle
|
4
|
-
.config
|
5
|
-
.yardoc
|
6
|
-
Gemfile.lock
|
7
|
-
InstalledFiles
|
8
|
-
_yardoc
|
9
|
-
coverage
|
10
|
-
doc/
|
11
|
-
lib/bundler/man
|
12
|
-
pkg
|
13
|
-
rdoc
|
14
|
-
spec/reports
|
15
|
-
test/tmp
|
16
|
-
test/version_tmp
|
17
|
-
tmp
|
18
|
-
.tags*
|
19
|
-
documentation/run/*
|
20
|
-
documentation/public/code/*
|
21
|
-
.rspec_status
|
data/.rspec
DELETED
data/.yardopts
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
--markup markdown
|
data/Gemfile
DELETED
@@ -1,19 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
source 'https://rubygems.org'
|
4
|
-
|
5
|
-
# Specify your gem's dependencies in utopia.gemspec
|
6
|
-
gemspec
|
7
|
-
|
8
|
-
group :development do
|
9
|
-
gem 'pry'
|
10
|
-
gem 'guard-rspec'
|
11
|
-
gem 'guard-yard'
|
12
|
-
|
13
|
-
gem 'yard'
|
14
|
-
end
|
15
|
-
|
16
|
-
group :test do
|
17
|
-
gem 'benchmark-ips'
|
18
|
-
gem 'ruby-prof', platforms: :mri
|
19
|
-
end
|
data/Guardfile
DELETED
@@ -1,14 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
directories %w(lib spec)
|
4
|
-
clearing :on
|
5
|
-
|
6
|
-
guard :rspec, cmd: "bundle exec rspec" do
|
7
|
-
watch(%r{^spec/.+_spec\.rb$})
|
8
|
-
watch(%r{^lib/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" }
|
9
|
-
watch("spec/spec_helper.rb") { "spec" }
|
10
|
-
end
|
11
|
-
|
12
|
-
guard 'yard', :port => '8808' do
|
13
|
-
watch(%r{^lib/(.+)\.rb$})
|
14
|
-
end
|
data/README.md
DELETED
@@ -1,140 +0,0 @@
|
|
1
|
-
# Async::Container
|
2
|
-
|
3
|
-
Provides containers which implement concurrency policy for high-level servers (and potentially clients).
|
4
|
-
|
5
|
-
[![Actions Status](https://github.com/socketry/async-container/workflows/Development/badge.svg)](https://github.com/socketry/async-container/actions?workflow=Development)
|
6
|
-
[![Code Climate](https://codeclimate.com/github/socketry/async-container.svg)](https://codeclimate.com/github/socketry/async-container)
|
7
|
-
[![Coverage Status](https://coveralls.io/repos/socketry/async-container/badge.svg)](https://coveralls.io/r/socketry/async-container)
|
8
|
-
|
9
|
-
## Installation
|
10
|
-
|
11
|
-
Add this line to your application's Gemfile:
|
12
|
-
|
13
|
-
```ruby
|
14
|
-
gem "async-container"
|
15
|
-
```
|
16
|
-
|
17
|
-
And then execute:
|
18
|
-
|
19
|
-
$ bundle
|
20
|
-
|
21
|
-
Or install it yourself as:
|
22
|
-
|
23
|
-
$ gem install async
|
24
|
-
|
25
|
-
## Usage
|
26
|
-
|
27
|
-
### Container
|
28
|
-
|
29
|
-
A container represents a set of child processes (or threads) which are doing work for you.
|
30
|
-
|
31
|
-
```ruby
|
32
|
-
require 'async/container'
|
33
|
-
|
34
|
-
Async.logger.debug!
|
35
|
-
|
36
|
-
container = Async::Container.new
|
37
|
-
|
38
|
-
container.async do |task|
|
39
|
-
task.logger.debug "Sleeping..."
|
40
|
-
task.sleep(1)
|
41
|
-
task.logger.debug "Waking up!"
|
42
|
-
end
|
43
|
-
|
44
|
-
Async.logger.debug "Waiting for container..."
|
45
|
-
container.wait
|
46
|
-
Async.logger.debug "Finished."
|
47
|
-
```
|
48
|
-
|
49
|
-
### Controller
|
50
|
-
|
51
|
-
The controller provides the life-cycle management for one or more containers of processes. It provides behaviour like starting, restarting, reloading and stopping. You can see some [example implementations in Falcon](https://github.com/socketry/falcon/blob/master/lib/falcon/controller/). If the process running the controller receives `SIGHUP` it will recreate the container gracefully.
|
52
|
-
|
53
|
-
```ruby
|
54
|
-
require 'async/container'
|
55
|
-
|
56
|
-
Async.logger.debug!
|
57
|
-
|
58
|
-
class Controller < Async::Container::Controller
|
59
|
-
def setup(container)
|
60
|
-
container.async do |task|
|
61
|
-
while true
|
62
|
-
Async.logger.debug("Sleeping...")
|
63
|
-
task.sleep(1)
|
64
|
-
end
|
65
|
-
end
|
66
|
-
end
|
67
|
-
end
|
68
|
-
|
69
|
-
controller = Controller.new
|
70
|
-
|
71
|
-
controller.run
|
72
|
-
|
73
|
-
# If you send SIGHUP to this process, it will recreate the container.
|
74
|
-
```
|
75
|
-
|
76
|
-
### Signal Handling
|
77
|
-
|
78
|
-
`SIGINT` is the interrupt signal. The terminal sends it to the foreground process when the user presses **ctrl-c**. The default behavior is to terminate the process, but it can be caught or ignored. The intention is to provide a mechanism for an orderly, graceful shutdown.
|
79
|
-
|
80
|
-
`SIGQUIT` is the dump core signal. The terminal sends it to the foreground process when the user presses **ctrl-\**. The default behavior is to terminate the process and dump core, but it can be caught or ignored. The intention is to provide a mechanism for the user to abort the process. You can look at `SIGINT` as "user-initiated happy termination" and `SIGQUIT` as "user-initiated unhappy termination."
|
81
|
-
|
82
|
-
`SIGTERM` is the termination signal. The default behavior is to terminate the process, but it also can be caught or ignored. The intention is to kill the process, gracefully or not, but to first allow it a chance to cleanup.
|
83
|
-
|
84
|
-
`SIGKILL` is the kill signal. The only behavior is to kill the process, immediately. As the process cannot catch the signal, it cannot cleanup, and thus this is a signal of last resort.
|
85
|
-
|
86
|
-
`SIGSTOP` is the pause signal. The only behavior is to pause the process; the signal cannot be caught or ignored. The shell uses pausing (and its counterpart, resuming via `SIGCONT`) to implement job control.
|
87
|
-
|
88
|
-
### Integration
|
89
|
-
|
90
|
-
#### systemd
|
91
|
-
|
92
|
-
Install a template file into `/etc/systemd/system/`:
|
93
|
-
|
94
|
-
```
|
95
|
-
# my-daemon.service
|
96
|
-
[Unit]
|
97
|
-
Description=My Daemon
|
98
|
-
AssertPathExists=/srv/
|
99
|
-
|
100
|
-
[Service]
|
101
|
-
Type=notify
|
102
|
-
WorkingDirectory=/srv/my-daemon
|
103
|
-
ExecStart=bundle exec my-daemon
|
104
|
-
Nice=5
|
105
|
-
|
106
|
-
[Install]
|
107
|
-
WantedBy=multi-user.target
|
108
|
-
```
|
109
|
-
|
110
|
-
## Contributing
|
111
|
-
|
112
|
-
1. Fork it
|
113
|
-
2. Create your feature branch (`git checkout -b my-new-feature`)
|
114
|
-
3. Commit your changes (`git commit -am 'Add some feature'`)
|
115
|
-
4. Push to the branch (`git push origin my-new-feature`)
|
116
|
-
5. Create new Pull Request
|
117
|
-
|
118
|
-
## License
|
119
|
-
|
120
|
-
Released under the MIT license.
|
121
|
-
|
122
|
-
Copyright, 2017, by [Samuel G. D. Williams](http://www.codeotaku.com/samuel-williams).
|
123
|
-
|
124
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
125
|
-
of this software and associated documentation files (the "Software"), to deal
|
126
|
-
in the Software without restriction, including without limitation the rights
|
127
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
128
|
-
copies of the Software, and to permit persons to whom the Software is
|
129
|
-
furnished to do so, subject to the following conditions:
|
130
|
-
|
131
|
-
The above copyright notice and this permission notice shall be included in
|
132
|
-
all copies or substantial portions of the Software.
|
133
|
-
|
134
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
135
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
136
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
137
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
138
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
139
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
140
|
-
THE SOFTWARE.
|