always 0.0.5 → 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 +10 -20
- data/.rultor.yml +4 -20
- data/.simplecov +2 -19
- data/Gemfile +12 -27
- data/Gemfile.lock +56 -144
- data/LICENSE.txt +1 -1
- data/LICENSES/MIT.txt +21 -0
- data/README.md +11 -7
- data/REUSE.toml +34 -0
- data/Rakefile +3 -30
- data/always.gemspec +4 -21
- data/lib/always.rb +29 -30
- data/test/test__helper.rb +22 -22
- data/test/test_always.rb +27 -28
- metadata +9 -8
- data/.github/workflows/license.yml +0 -57
data/Gemfile.lock
CHANGED
@@ -7,141 +7,55 @@ PATH
|
|
7
7
|
GEM
|
8
8
|
remote: https://rubygems.org/
|
9
9
|
specs:
|
10
|
-
|
11
|
-
|
12
|
-
activesupport (= 7.1.3.4)
|
13
|
-
nokogiri (>= 1.8.5)
|
14
|
-
racc
|
15
|
-
rack (>= 2.2.4)
|
16
|
-
rack-session (>= 1.0.1)
|
17
|
-
rack-test (>= 0.6.3)
|
18
|
-
rails-dom-testing (~> 2.2)
|
19
|
-
rails-html-sanitizer (~> 1.6)
|
20
|
-
actionview (7.1.3.4)
|
21
|
-
activesupport (= 7.1.3.4)
|
22
|
-
builder (~> 3.1)
|
23
|
-
erubi (~> 1.11)
|
24
|
-
rails-dom-testing (~> 2.2)
|
25
|
-
rails-html-sanitizer (~> 1.6)
|
26
|
-
activesupport (7.1.3.4)
|
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)
|
10
|
+
ansi (1.5.0)
|
11
|
+
ast (2.4.3)
|
39
12
|
builder (3.3.0)
|
40
|
-
concurrent-ruby (1.3.
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
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.24.1)
|
59
|
-
mutex_m (0.2.0)
|
60
|
-
nokogiri (1.16.6-aarch64-linux)
|
61
|
-
racc (~> 1.4)
|
62
|
-
nokogiri (1.16.6-arm-linux)
|
63
|
-
racc (~> 1.4)
|
64
|
-
nokogiri (1.16.6-arm64-darwin)
|
65
|
-
racc (~> 1.4)
|
66
|
-
nokogiri (1.16.6-x64-mingw-ucrt)
|
67
|
-
racc (~> 1.4)
|
68
|
-
nokogiri (1.16.6-x86-linux)
|
69
|
-
racc (~> 1.4)
|
70
|
-
nokogiri (1.16.6-x86_64-darwin)
|
71
|
-
racc (~> 1.4)
|
72
|
-
nokogiri (1.16.6-x86_64-linux)
|
73
|
-
racc (~> 1.4)
|
74
|
-
parallel (1.25.1)
|
75
|
-
parser (3.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.1.6)
|
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.4)
|
97
|
-
actionpack (= 7.1.3.4)
|
98
|
-
activesupport (= 7.1.3.4)
|
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.9)
|
110
|
-
io-console (~> 0.5)
|
111
|
-
rexml (3.3.1)
|
112
|
-
strscan
|
113
|
-
rspec-core (3.13.0)
|
114
|
-
rspec-support (~> 3.13.0)
|
115
|
-
rspec-expectations (3.13.1)
|
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.3)
|
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
|
-
|
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)
|
145
59
|
ruby-progressbar (1.13.0)
|
146
60
|
simplecov (0.22.0)
|
147
61
|
docile (~> 1.1)
|
@@ -150,22 +64,18 @@ GEM
|
|
150
64
|
simplecov-cobertura (2.1.0)
|
151
65
|
rexml
|
152
66
|
simplecov (~> 0.19)
|
153
|
-
simplecov-html (0.
|
67
|
+
simplecov-html (0.13.1)
|
154
68
|
simplecov_json_formatter (0.1.4)
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
concurrent-ruby (~> 1.0)
|
160
|
-
unicode-display_width (2.5.0)
|
161
|
-
webrick (1.8.1)
|
162
|
-
yard (0.9.36)
|
163
|
-
zeitwerk (2.6.16)
|
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)
|
164
73
|
|
165
74
|
PLATFORMS
|
166
75
|
aarch64-linux
|
167
76
|
arm-linux
|
168
77
|
arm64-darwin
|
78
|
+
arm64-darwin-23
|
169
79
|
x64-mingw-ucrt
|
170
80
|
x86-linux
|
171
81
|
x86_64-darwin
|
@@ -173,14 +83,16 @@ PLATFORMS
|
|
173
83
|
|
174
84
|
DEPENDENCIES
|
175
85
|
always!
|
176
|
-
minitest (
|
177
|
-
|
178
|
-
|
179
|
-
rubocop (
|
180
|
-
rubocop-
|
181
|
-
|
182
|
-
|
183
|
-
|
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)
|
184
96
|
|
185
97
|
BUNDLED WITH
|
186
|
-
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
|
|
@@ -18,7 +18,7 @@ require 'always'
|
|
18
18
|
# Prepare, with five threads:
|
19
19
|
a = Always.new(5)
|
20
20
|
# Start them all together spinning forever with 30-seconds delay between cycles:
|
21
|
-
a.start do
|
21
|
+
a.start(30) do
|
22
22
|
puts "I'm alive"
|
23
23
|
end
|
24
24
|
# Stop them all together:
|
@@ -31,7 +31,11 @@ happened most recently:
|
|
31
31
|
```ruby
|
32
32
|
# Keep the last 10 error backtraces in memory:
|
33
33
|
a = Always.new(5, max_backtraces: 10)
|
34
|
-
#
|
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:
|
35
39
|
p a.backtraces
|
36
40
|
```
|
37
41
|
|
@@ -41,7 +45,7 @@ That's it.
|
|
41
45
|
|
42
46
|
Read
|
43
47
|
[these guidelines](https://www.yegor256.com/2014/04/15/github-guidelines.html).
|
44
|
-
Make sure
|
48
|
+
Make sure your build is green before you contribute
|
45
49
|
your pull request. You will need to have
|
46
50
|
[Ruby](https://www.ruby-lang.org/en/) 3.0+ and
|
47
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,7 +14,7 @@ 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
20
|
# Then, in order to stop them all together:
|
@@ -43,22 +27,30 @@ require 'concurrent/atom'
|
|
43
27
|
# so far, and +E+ is the total number of all errors seen so far.
|
44
28
|
#
|
45
29
|
# Author:: Yegor Bugayenko (yegor256@gmail.com)
|
46
|
-
# Copyright:: Copyright (c) 2024 Yegor Bugayenko
|
30
|
+
# Copyright:: Copyright (c) 2024-2025 Yegor Bugayenko
|
47
31
|
# License:: MIT
|
48
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
|
49
40
|
attr_reader :backtraces
|
50
41
|
|
51
42
|
# The version of the framework.
|
52
|
-
VERSION = '0.0
|
43
|
+
VERSION = '0.1.0'
|
53
44
|
|
54
45
|
# Constructor.
|
55
46
|
# @param [Integer] total The number of threads to run
|
56
47
|
# @param [Integer] max_backtraces How many backtraces to keep in memory?
|
57
|
-
def initialize(total, max_backtraces: 32)
|
48
|
+
def initialize(total, max_backtraces: 32, name: "always-#{SecureRandom.hex(4)}")
|
58
49
|
raise "The number of threads (#{total}) must be positive" unless total.positive?
|
59
50
|
|
60
51
|
@total = total
|
61
52
|
@on_error = nil
|
53
|
+
@name = name
|
62
54
|
@threads = []
|
63
55
|
@backtraces = []
|
64
56
|
@cycles = Concurrent::Atom.new(0)
|
@@ -69,7 +61,7 @@ class Always
|
|
69
61
|
# What to do when an exception occurs?
|
70
62
|
#
|
71
63
|
# Call it like this (the +e+ provided is the exception and +i+ is the
|
72
|
-
# number of the thread where it
|
64
|
+
# number of the thread where it occurred):
|
73
65
|
#
|
74
66
|
# a = Always.new(5)
|
75
67
|
# a.on_error do |e, i|
|
@@ -90,9 +82,12 @@ class Always
|
|
90
82
|
raise 'It is running now, call .stop() first' unless @threads.empty?
|
91
83
|
|
92
84
|
(0..@total - 1).each do |i|
|
93
|
-
|
94
|
-
|
95
|
-
|
85
|
+
t =
|
86
|
+
Thread.new do
|
87
|
+
body(pause, &)
|
88
|
+
end
|
89
|
+
t.name = "#{@name}-#{i + 1}"
|
90
|
+
@threads[i] = t
|
96
91
|
end
|
97
92
|
end
|
98
93
|
|
@@ -111,8 +106,12 @@ class Always
|
|
111
106
|
|
112
107
|
# Represent its internal state as a string.
|
113
108
|
# @return [String] Something like "4/230/23", where 4 is the number of running
|
114
|
-
# threads, 230 is the number of
|
115
|
-
# 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"
|
116
115
|
def to_s
|
117
116
|
"#{@threads.size}/#{@cycles.value}/#{@errors.value}"
|
118
117
|
end
|
@@ -140,7 +139,7 @@ class Always
|
|
140
139
|
@errors.swap { |c| c + 1 }
|
141
140
|
@backtraces << e
|
142
141
|
@backtraces.shift if @backtraces.size > @max_backtraces
|
143
|
-
@on_error&.call(e)
|
142
|
+
@on_error&.call(e, Thread.current.object_id)
|
144
143
|
end
|
145
144
|
# rubocop:enable Lint/RescueException
|
146
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]
|