always 0.0.4 → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.0pdd.yml +2 -19
- data/.github/workflows/actionlint.yml +5 -21
- data/.github/workflows/codecov.yml +9 -23
- data/.github/workflows/copyrights.yml +19 -0
- data/.github/workflows/markdown-lint.yml +6 -21
- data/.github/workflows/pdd.yml +6 -21
- data/.github/workflows/rake.yml +8 -24
- data/.github/workflows/reuse.yml +19 -0
- data/.github/workflows/typos.yml +19 -0
- data/.github/workflows/xcop.yml +6 -21
- data/.github/workflows/yamllint.yml +5 -20
- data/.gitignore +8 -6
- data/.rubocop.yml +12 -20
- data/.rultor.yml +4 -20
- data/.simplecov +2 -19
- data/Gemfile +12 -27
- data/Gemfile.lock +57 -154
- data/LICENSE.txt +1 -1
- data/LICENSES/MIT.txt +21 -0
- data/README.md +25 -9
- data/REUSE.toml +34 -0
- data/Rakefile +3 -30
- data/always.gemspec +4 -21
- data/lib/always.rb +41 -32
- data/test/test__helper.rb +22 -22
- data/test/test_always.rb +50 -25
- metadata +9 -8
- data/.github/workflows/license.yml +0 -57
data/Gemfile.lock
CHANGED
@@ -7,150 +7,55 @@ PATH
|
|
7
7
|
GEM
|
8
8
|
remote: https://rubygems.org/
|
9
9
|
specs:
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
activesupport (7.1.3.3)
|
27
|
-
base64
|
28
|
-
bigdecimal
|
29
|
-
concurrent-ruby (~> 1.0, >= 1.0.2)
|
30
|
-
connection_pool (>= 2.2.5)
|
31
|
-
drb
|
32
|
-
i18n (>= 1.6, < 2)
|
33
|
-
minitest (>= 5.1)
|
34
|
-
mutex_m
|
35
|
-
tzinfo (~> 2.0)
|
36
|
-
ast (2.4.2)
|
37
|
-
base64 (0.2.0)
|
38
|
-
bigdecimal (3.1.8)
|
39
|
-
builder (3.2.4)
|
40
|
-
concurrent-ruby (1.3.1)
|
41
|
-
connection_pool (2.4.1)
|
42
|
-
crass (1.0.6)
|
43
|
-
diff-lcs (1.5.1)
|
44
|
-
docile (1.4.0)
|
45
|
-
drb (2.2.1)
|
46
|
-
erubi (1.12.0)
|
47
|
-
i18n (1.14.5)
|
48
|
-
concurrent-ruby (~> 1.0)
|
49
|
-
io-console (0.7.2)
|
50
|
-
irb (1.13.1)
|
51
|
-
rdoc (>= 4.0.0)
|
52
|
-
reline (>= 0.4.2)
|
53
|
-
json (2.7.2)
|
54
|
-
language_server-protocol (3.17.0.3)
|
55
|
-
loofah (2.22.0)
|
56
|
-
crass (~> 1.0.2)
|
57
|
-
nokogiri (>= 1.12.0)
|
58
|
-
minitest (5.23.1)
|
59
|
-
mutex_m (0.2.0)
|
60
|
-
nokogiri (1.16.5-aarch64-linux)
|
61
|
-
racc (~> 1.4)
|
62
|
-
nokogiri (1.16.5-arm-linux)
|
63
|
-
racc (~> 1.4)
|
64
|
-
nokogiri (1.16.5-arm64-darwin)
|
65
|
-
racc (~> 1.4)
|
66
|
-
nokogiri (1.16.5-x64-mingw-ucrt)
|
67
|
-
racc (~> 1.4)
|
68
|
-
nokogiri (1.16.5-x86-linux)
|
69
|
-
racc (~> 1.4)
|
70
|
-
nokogiri (1.16.5-x86_64-darwin)
|
71
|
-
racc (~> 1.4)
|
72
|
-
nokogiri (1.16.5-x86_64-linux)
|
73
|
-
racc (~> 1.4)
|
74
|
-
parallel (1.24.0)
|
75
|
-
parser (3.3.2.0)
|
10
|
+
ansi (1.5.0)
|
11
|
+
ast (2.4.3)
|
12
|
+
builder (3.3.0)
|
13
|
+
concurrent-ruby (1.3.5)
|
14
|
+
docile (1.4.1)
|
15
|
+
json (2.12.0)
|
16
|
+
language_server-protocol (3.17.0.5)
|
17
|
+
lint_roller (1.1.0)
|
18
|
+
minitest (5.25.5)
|
19
|
+
minitest-reporters (1.7.1)
|
20
|
+
ansi
|
21
|
+
builder
|
22
|
+
minitest (>= 5.0)
|
23
|
+
ruby-progressbar
|
24
|
+
parallel (1.27.0)
|
25
|
+
parser (3.3.8.0)
|
76
26
|
ast (~> 2.4.1)
|
77
27
|
racc
|
78
|
-
|
79
|
-
|
80
|
-
racc (1.8.0)
|
81
|
-
rack (3.0.11)
|
82
|
-
rack-session (2.0.0)
|
83
|
-
rack (>= 3.0.0)
|
84
|
-
rack-test (2.1.0)
|
85
|
-
rack (>= 1.3)
|
86
|
-
rackup (2.1.0)
|
87
|
-
rack (>= 3)
|
88
|
-
webrick (~> 1.8)
|
89
|
-
rails-dom-testing (2.2.0)
|
90
|
-
activesupport (>= 5.0.0)
|
91
|
-
minitest
|
92
|
-
nokogiri (>= 1.6)
|
93
|
-
rails-html-sanitizer (1.6.0)
|
94
|
-
loofah (~> 2.21)
|
95
|
-
nokogiri (~> 1.14)
|
96
|
-
railties (7.1.3.3)
|
97
|
-
actionpack (= 7.1.3.3)
|
98
|
-
activesupport (= 7.1.3.3)
|
99
|
-
irb
|
100
|
-
rackup (>= 1.0.0)
|
101
|
-
rake (>= 12.2)
|
102
|
-
thor (~> 1.0, >= 1.2.2)
|
103
|
-
zeitwerk (~> 2.6)
|
28
|
+
prism (1.4.0)
|
29
|
+
racc (1.8.1)
|
104
30
|
rainbow (3.1.1)
|
105
31
|
rake (13.2.1)
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
reline (0.5.8)
|
110
|
-
io-console (~> 0.5)
|
111
|
-
rexml (3.2.8)
|
112
|
-
strscan (>= 3.0.9)
|
113
|
-
rspec-core (3.13.0)
|
114
|
-
rspec-support (~> 3.13.0)
|
115
|
-
rspec-expectations (3.13.0)
|
116
|
-
diff-lcs (>= 1.2.0, < 2.0)
|
117
|
-
rspec-support (~> 3.13.0)
|
118
|
-
rspec-mocks (3.13.1)
|
119
|
-
diff-lcs (>= 1.2.0, < 2.0)
|
120
|
-
rspec-support (~> 3.13.0)
|
121
|
-
rspec-rails (6.1.2)
|
122
|
-
actionpack (>= 6.1)
|
123
|
-
activesupport (>= 6.1)
|
124
|
-
railties (>= 6.1)
|
125
|
-
rspec-core (~> 3.13)
|
126
|
-
rspec-expectations (~> 3.13)
|
127
|
-
rspec-mocks (~> 3.13)
|
128
|
-
rspec-support (~> 3.13)
|
129
|
-
rspec-support (3.13.1)
|
130
|
-
rubocop (1.64.1)
|
32
|
+
regexp_parser (2.10.0)
|
33
|
+
rexml (3.4.1)
|
34
|
+
rubocop (1.75.6)
|
131
35
|
json (~> 2.3)
|
132
|
-
language_server-protocol (
|
36
|
+
language_server-protocol (~> 3.17.0.2)
|
37
|
+
lint_roller (~> 1.1.0)
|
133
38
|
parallel (~> 1.10)
|
134
39
|
parser (>= 3.3.0.2)
|
135
40
|
rainbow (>= 2.2.2, < 4.0)
|
136
|
-
regexp_parser (>=
|
137
|
-
|
138
|
-
rubocop-ast (>= 1.31.1, < 2.0)
|
41
|
+
regexp_parser (>= 2.9.3, < 3.0)
|
42
|
+
rubocop-ast (>= 1.44.0, < 2.0)
|
139
43
|
ruby-progressbar (~> 1.7)
|
140
|
-
unicode-display_width (>= 2.4.0, <
|
141
|
-
rubocop-ast (1.
|
142
|
-
parser (>= 3.3.
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
rubocop (
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
rubocop
|
151
|
-
rubocop-
|
152
|
-
rubocop-
|
153
|
-
|
44
|
+
unicode-display_width (>= 2.4.0, < 4.0)
|
45
|
+
rubocop-ast (1.44.1)
|
46
|
+
parser (>= 3.3.7.2)
|
47
|
+
prism (~> 1.4)
|
48
|
+
rubocop-minitest (0.38.0)
|
49
|
+
lint_roller (~> 1.1)
|
50
|
+
rubocop (>= 1.75.0, < 2.0)
|
51
|
+
rubocop-ast (>= 1.38.0, < 2.0)
|
52
|
+
rubocop-performance (1.25.0)
|
53
|
+
lint_roller (~> 1.1)
|
54
|
+
rubocop (>= 1.75.0, < 2.0)
|
55
|
+
rubocop-ast (>= 1.38.0, < 2.0)
|
56
|
+
rubocop-rake (0.7.1)
|
57
|
+
lint_roller (~> 1.1)
|
58
|
+
rubocop (>= 1.72.1)
|
154
59
|
ruby-progressbar (1.13.0)
|
155
60
|
simplecov (0.22.0)
|
156
61
|
docile (~> 1.1)
|
@@ -159,22 +64,18 @@ GEM
|
|
159
64
|
simplecov-cobertura (2.1.0)
|
160
65
|
rexml
|
161
66
|
simplecov (~> 0.19)
|
162
|
-
simplecov-html (0.
|
67
|
+
simplecov-html (0.13.1)
|
163
68
|
simplecov_json_formatter (0.1.4)
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
concurrent-ruby (~> 1.0)
|
169
|
-
unicode-display_width (2.5.0)
|
170
|
-
webrick (1.8.1)
|
171
|
-
yard (0.9.36)
|
172
|
-
zeitwerk (2.6.15)
|
69
|
+
unicode-display_width (3.1.4)
|
70
|
+
unicode-emoji (~> 4.0, >= 4.0.4)
|
71
|
+
unicode-emoji (4.0.4)
|
72
|
+
yard (0.9.37)
|
173
73
|
|
174
74
|
PLATFORMS
|
175
75
|
aarch64-linux
|
176
76
|
arm-linux
|
177
77
|
arm64-darwin
|
78
|
+
arm64-darwin-23
|
178
79
|
x64-mingw-ucrt
|
179
80
|
x86-linux
|
180
81
|
x86_64-darwin
|
@@ -182,14 +83,16 @@ PLATFORMS
|
|
182
83
|
|
183
84
|
DEPENDENCIES
|
184
85
|
always!
|
185
|
-
minitest (
|
186
|
-
|
187
|
-
|
188
|
-
rubocop (
|
189
|
-
rubocop-
|
190
|
-
|
191
|
-
|
192
|
-
|
86
|
+
minitest (~> 5.25)
|
87
|
+
minitest-reporters (~> 1.7)
|
88
|
+
rake (~> 13.2)
|
89
|
+
rubocop (~> 1.64)
|
90
|
+
rubocop-minitest (> 0)
|
91
|
+
rubocop-performance (> 0)
|
92
|
+
rubocop-rake (> 0)
|
93
|
+
simplecov (~> 0.22)
|
94
|
+
simplecov-cobertura (~> 2.1)
|
95
|
+
yard (~> 0.9)
|
193
96
|
|
194
97
|
BUNDLED WITH
|
195
|
-
2.5.
|
98
|
+
2.5.16
|
data/LICENSE.txt
CHANGED
data/LICENSES/MIT.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
(The MIT License)
|
2
|
+
|
3
|
+
Copyright (c) 2024-2025 Yegor Bugayenko
|
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 all
|
13
|
+
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 THE
|
21
|
+
SOFTWARE.
|
data/README.md
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
# Runs a Background Loop Forever
|
2
2
|
|
3
|
-
[](https://www.rultor.com/p/yegor256/always)
|
4
4
|
[](https://www.jetbrains.com/ruby/)
|
5
5
|
|
6
6
|
[](https://github.com/yegor256/always/actions/workflows/rake.yml)
|
7
|
-
[](
|
7
|
+
[](https://www.0pdd.com/p?name=yegor256/always)
|
8
|
+
[](https://badge.fury.io/rb/always)
|
9
9
|
[](https://codecov.io/github/yegor256/always?branch=master)
|
10
|
-
[](https://rubydoc.info/github/yegor256/always/master/frames)
|
11
11
|
[](https://hitsofcode.com/view/github/yegor256/always)
|
12
12
|
[](https://github.com/yegor256/always/blob/master/LICENSE.txt)
|
13
13
|
|
@@ -15,21 +15,37 @@ This simple Ruby gem helps you run a loop forever, in a background thread.
|
|
15
15
|
|
16
16
|
```ruby
|
17
17
|
require 'always'
|
18
|
-
# Prepare, with five threads
|
19
|
-
a = Always.new(5
|
20
|
-
# Start them all together spinning forever:
|
21
|
-
a.start do
|
18
|
+
# Prepare, with five threads:
|
19
|
+
a = Always.new(5)
|
20
|
+
# Start them all together spinning forever with 30-seconds delay between cycles:
|
21
|
+
a.start(30) do
|
22
22
|
puts "I'm alive"
|
23
23
|
end
|
24
24
|
# Stop them all together:
|
25
25
|
a.stop
|
26
26
|
```
|
27
27
|
|
28
|
+
You may be interested to get the backtraces of the exceptions that
|
29
|
+
happened most recently:
|
30
|
+
|
31
|
+
```ruby
|
32
|
+
# Keep the last 10 error backtraces in memory:
|
33
|
+
a = Always.new(5, max_backtraces: 10)
|
34
|
+
# Set an error handler:
|
35
|
+
a.on_error do |exception, thread_id|
|
36
|
+
puts "Error in thread #{thread_id}: #{exception.message}"
|
37
|
+
end
|
38
|
+
# Retrieve the backtraces:
|
39
|
+
p a.backtraces
|
40
|
+
```
|
41
|
+
|
42
|
+
That's it.
|
43
|
+
|
28
44
|
## How to contribute
|
29
45
|
|
30
46
|
Read
|
31
47
|
[these guidelines](https://www.yegor256.com/2014/04/15/github-guidelines.html).
|
32
|
-
Make sure
|
48
|
+
Make sure your build is green before you contribute
|
33
49
|
your pull request. You will need to have
|
34
50
|
[Ruby](https://www.ruby-lang.org/en/) 3.0+ and
|
35
51
|
[Bundler](https://bundler.io/) installed. Then:
|
data/REUSE.toml
ADDED
@@ -0,0 +1,34 @@
|
|
1
|
+
# SPDX-FileCopyrightText: Copyright (c) 2025 Yegor Bugayenko
|
2
|
+
# SPDX-License-Identifier: MIT
|
3
|
+
|
4
|
+
version = 1
|
5
|
+
[[annotations]]
|
6
|
+
path = [
|
7
|
+
".DS_Store",
|
8
|
+
".gitattributes",
|
9
|
+
".gitignore",
|
10
|
+
".pdd",
|
11
|
+
"**.json",
|
12
|
+
"**.md",
|
13
|
+
"**.txt",
|
14
|
+
"**/.DS_Store",
|
15
|
+
"**/.gitignore",
|
16
|
+
"**/.pdd",
|
17
|
+
"**/*.csv",
|
18
|
+
"**/*.jpg",
|
19
|
+
"**/*.json",
|
20
|
+
"**/*.md",
|
21
|
+
"**/*.pdf",
|
22
|
+
"**/*.png",
|
23
|
+
"**/*.svg",
|
24
|
+
"**/*.txt",
|
25
|
+
"**/*.vm",
|
26
|
+
"**/CNAME",
|
27
|
+
"**/Gemfile.lock",
|
28
|
+
"Gemfile.lock",
|
29
|
+
"README.md",
|
30
|
+
"renovate.json",
|
31
|
+
]
|
32
|
+
precedence = "override"
|
33
|
+
SPDX-FileCopyrightText = "Copyright (c) 2025 Yegor Bugayenko"
|
34
|
+
SPDX-License-Identifier = "MIT"
|
data/Rakefile
CHANGED
@@ -1,24 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
# Copyright (c) 2024 Yegor Bugayenko
|
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 all
|
13
|
-
# 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 THE
|
21
|
-
# SOFTWARE.
|
3
|
+
# SPDX-FileCopyrightText: Copyright (c) 2024-2025 Yegor Bugayenko
|
4
|
+
# SPDX-License-Identifier: MIT
|
22
5
|
|
23
6
|
require 'rubygems'
|
24
7
|
require 'rake'
|
@@ -33,7 +16,7 @@ def version
|
|
33
16
|
Gem::Specification.load(Dir['*.gemspec'].first).version
|
34
17
|
end
|
35
18
|
|
36
|
-
task default: %i[clean test rubocop yard
|
19
|
+
task default: %i[clean test rubocop yard]
|
37
20
|
|
38
21
|
require 'rake/testtask'
|
39
22
|
desc 'Run all unit tests'
|
@@ -55,14 +38,4 @@ require 'rubocop/rake_task'
|
|
55
38
|
desc 'Run RuboCop on all directories'
|
56
39
|
RuboCop::RakeTask.new(:rubocop) do |task|
|
57
40
|
task.fail_on_error = true
|
58
|
-
task.requires << 'rubocop-rspec'
|
59
|
-
end
|
60
|
-
|
61
|
-
task :copyright do
|
62
|
-
sh "grep -q -r '#{Date.today.strftime('%Y')}' \
|
63
|
-
--include '*.rb' \
|
64
|
-
--include '*.yml' \
|
65
|
-
--include '*.txt' \
|
66
|
-
--include 'Rakefile' \
|
67
|
-
."
|
68
41
|
end
|
data/always.gemspec
CHANGED
@@ -1,24 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
# Copyright (c) 2024 Yegor Bugayenko
|
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 all
|
13
|
-
# 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 THE
|
21
|
-
# SOFTWARE.
|
3
|
+
# SPDX-FileCopyrightText: Copyright (c) 2024-2025 Yegor Bugayenko
|
4
|
+
# SPDX-License-Identifier: MIT
|
22
5
|
|
23
6
|
require 'English'
|
24
7
|
|
@@ -26,7 +9,7 @@ Gem::Specification.new do |s|
|
|
26
9
|
s.required_rubygems_version = Gem::Requirement.new('>= 0') if s.respond_to? :required_rubygems_version=
|
27
10
|
s.required_ruby_version = '>=3.2'
|
28
11
|
s.name = 'always'
|
29
|
-
s.version = '0.0
|
12
|
+
s.version = '0.1.0'
|
30
13
|
s.license = 'MIT'
|
31
14
|
s.summary = 'A simple Ruby framework that spins a loop forever, in a background thread'
|
32
15
|
s.description =
|
@@ -40,6 +23,6 @@ Gem::Specification.new do |s|
|
|
40
23
|
s.executables = s.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
41
24
|
s.rdoc_options = ['--charset=UTF-8']
|
42
25
|
s.extra_rdoc_files = ['README.md', 'LICENSE.txt']
|
43
|
-
s.
|
26
|
+
s.add_dependency 'concurrent-ruby', '~>1.1'
|
44
27
|
s.metadata['rubygems_mfa_required'] = 'true'
|
45
28
|
end
|
data/lib/always.rb
CHANGED
@@ -1,26 +1,10 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
# Copyright (c) 2024 Yegor Bugayenko
|
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 all
|
13
|
-
# 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 THE
|
21
|
-
# SOFTWARE.
|
3
|
+
# SPDX-FileCopyrightText: Copyright (c) 2024-2025 Yegor Bugayenko
|
4
|
+
# SPDX-License-Identifier: MIT
|
22
5
|
|
23
6
|
require 'concurrent/atom'
|
7
|
+
require 'securerandom'
|
24
8
|
|
25
9
|
# Always.
|
26
10
|
#
|
@@ -30,38 +14,54 @@ require 'concurrent/atom'
|
|
30
14
|
# require 'always'
|
31
15
|
# a = Always.new(5)
|
32
16
|
# a.start(60) do
|
33
|
-
# puts 'Hello, world!
|
17
|
+
# puts 'Hello, world!'
|
34
18
|
# end
|
35
19
|
#
|
36
|
-
# Then, in order stop them all together:
|
20
|
+
# Then, in order to stop them all together:
|
37
21
|
#
|
38
22
|
# a.stop
|
39
23
|
#
|
40
24
|
# It's possible to get a quick summary of the thread pool, by calling +to_s+.
|
25
|
+
# The result will be a +"T/C/E"+ string, where +T+ is the total number of
|
26
|
+
# currently running threads, +C+ is the total number of all cycles
|
27
|
+
# so far, and +E+ is the total number of all errors seen so far.
|
41
28
|
#
|
42
29
|
# Author:: Yegor Bugayenko (yegor256@gmail.com)
|
43
|
-
# Copyright:: Copyright (c) 2024 Yegor Bugayenko
|
30
|
+
# Copyright:: Copyright (c) 2024-2025 Yegor Bugayenko
|
44
31
|
# License:: MIT
|
45
32
|
class Always
|
33
|
+
# Get the array of most recent exception backtraces.
|
34
|
+
# @return [Array<Exception>] The array of exceptions caught
|
35
|
+
# @example
|
36
|
+
# a = Always.new(5, max_backtraces: 10)
|
37
|
+
# a.start { raise 'Oops' }
|
38
|
+
# sleep 1
|
39
|
+
# puts a.backtraces.size # => number of exceptions caught
|
40
|
+
attr_reader :backtraces
|
41
|
+
|
46
42
|
# The version of the framework.
|
47
|
-
VERSION = '0.0
|
43
|
+
VERSION = '0.1.0'
|
48
44
|
|
49
45
|
# Constructor.
|
50
46
|
# @param [Integer] total The number of threads to run
|
51
|
-
|
47
|
+
# @param [Integer] max_backtraces How many backtraces to keep in memory?
|
48
|
+
def initialize(total, max_backtraces: 32, name: "always-#{SecureRandom.hex(4)}")
|
52
49
|
raise "The number of threads (#{total}) must be positive" unless total.positive?
|
53
50
|
|
54
51
|
@total = total
|
55
52
|
@on_error = nil
|
53
|
+
@name = name
|
56
54
|
@threads = []
|
55
|
+
@backtraces = []
|
57
56
|
@cycles = Concurrent::Atom.new(0)
|
58
57
|
@errors = Concurrent::Atom.new(0)
|
58
|
+
@max_backtraces = max_backtraces
|
59
59
|
end
|
60
60
|
|
61
61
|
# What to do when an exception occurs?
|
62
62
|
#
|
63
63
|
# Call it like this (the +e+ provided is the exception and +i+ is the
|
64
|
-
# number of the thread where it
|
64
|
+
# number of the thread where it occurred):
|
65
65
|
#
|
66
66
|
# a = Always.new(5)
|
67
67
|
# a.on_error do |e, i|
|
@@ -76,15 +76,18 @@ class Always
|
|
76
76
|
self
|
77
77
|
end
|
78
78
|
|
79
|
-
# Start them all.
|
79
|
+
# Start them all and let them run forever (until the +stop+ method is called).
|
80
80
|
# @param [Integer] pause The delay between cycles, in seconds
|
81
81
|
def start(pause = 0, &)
|
82
82
|
raise 'It is running now, call .stop() first' unless @threads.empty?
|
83
83
|
|
84
84
|
(0..@total - 1).each do |i|
|
85
|
-
|
86
|
-
|
87
|
-
|
85
|
+
t =
|
86
|
+
Thread.new do
|
87
|
+
body(pause, &)
|
88
|
+
end
|
89
|
+
t.name = "#{@name}-#{i + 1}"
|
90
|
+
@threads[i] = t
|
88
91
|
end
|
89
92
|
end
|
90
93
|
|
@@ -103,8 +106,12 @@ class Always
|
|
103
106
|
|
104
107
|
# Represent its internal state as a string.
|
105
108
|
# @return [String] Something like "4/230/23", where 4 is the number of running
|
106
|
-
# threads, 230 is the number of
|
107
|
-
# of failures
|
109
|
+
# threads, 230 is the number of successful loops, and 23 is the number
|
110
|
+
# of failures occurred so far.
|
111
|
+
# @example
|
112
|
+
# a = Always.new(5)
|
113
|
+
# a.start(60) { puts 'Working...' }
|
114
|
+
# puts a.to_s # => "5/42/3"
|
108
115
|
def to_s
|
109
116
|
"#{@threads.size}/#{@cycles.value}/#{@errors.value}"
|
110
117
|
end
|
@@ -130,7 +137,9 @@ class Always
|
|
130
137
|
yield
|
131
138
|
rescue Exception => e
|
132
139
|
@errors.swap { |c| c + 1 }
|
133
|
-
@
|
140
|
+
@backtraces << e
|
141
|
+
@backtraces.shift if @backtraces.size > @max_backtraces
|
142
|
+
@on_error&.call(e, Thread.current.object_id)
|
134
143
|
end
|
135
144
|
# rubocop:enable Lint/RescueException
|
136
145
|
end
|
data/test/test__helper.rb
CHANGED
@@ -1,31 +1,31 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
# Copyright (c) 2024 Yegor Bugayenko
|
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 all
|
13
|
-
# 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 THE
|
21
|
-
# SOFTWARE.
|
3
|
+
# SPDX-FileCopyrightText: Copyright (c) 2024-2025 Yegor Bugayenko
|
4
|
+
# SPDX-License-Identifier: MIT
|
22
5
|
|
23
6
|
$stdout.sync = true
|
24
7
|
|
25
8
|
require 'simplecov'
|
26
|
-
SimpleCov.start
|
27
|
-
|
28
9
|
require 'simplecov-cobertura'
|
29
|
-
SimpleCov.
|
10
|
+
unless SimpleCov.running || ENV['PICKS']
|
11
|
+
SimpleCov.command_name('test')
|
12
|
+
SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter.new(
|
13
|
+
[
|
14
|
+
SimpleCov::Formatter::HTMLFormatter,
|
15
|
+
SimpleCov::Formatter::CoberturaFormatter
|
16
|
+
]
|
17
|
+
)
|
18
|
+
SimpleCov.minimum_coverage 95
|
19
|
+
SimpleCov.minimum_coverage_by_file 90
|
20
|
+
SimpleCov.start do
|
21
|
+
add_filter 'test/'
|
22
|
+
add_filter 'vendor/'
|
23
|
+
add_filter 'target/'
|
24
|
+
track_files 'lib/**/*.rb'
|
25
|
+
track_files '*.rb'
|
26
|
+
end
|
27
|
+
end
|
30
28
|
|
31
29
|
require 'minitest/autorun'
|
30
|
+
require 'minitest/reporters'
|
31
|
+
Minitest::Reporters.use! [Minitest::Reporters::SpecReporter.new]
|