sigurd 0.0.3 → 0.1.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
  SHA256:
3
- metadata.gz: f07c122083a1660b13660365c50697540880b435529921f610132d9812670b92
4
- data.tar.gz: a3f8c982afe4b4c798e14c76ba14aa5e8dab8acaa829c775ba47f5bbd7ccba2c
3
+ metadata.gz: 78b91ee76ef004d00edc84bba38adfdc5c53987574ab27f4843a555553d5753a
4
+ data.tar.gz: 786a1fe84d80e7b37f920c1b977e6a2957cd6b174bb86c34a82eb0785e7760db
5
5
  SHA512:
6
- metadata.gz: 66054bbcae792d1ffdf96a2a3688a03123aa995b09b33e0f90c89901fc8b195a5675941524591dd8bb75452259d204b19e209d87dd2d5ed7de15ed6e193e660a
7
- data.tar.gz: aaadff9649837dc5448850a6c23acfd6ba3c2d85642eaa2e7dcfce9bb26bbf3f85a81c994174080a8aaf0e46a874ba6036035d6c8db905f065bbd297a06e6286
6
+ metadata.gz: 03edd2b5c68e976c9b3b0de4395dc448b8b95c28939547e6d2eb6ebe1376bae177e6da7de92e8f5aed99a6b51bc81b9ba06b32a263ad3d65252b81b23544f714
7
+ data.tar.gz: 54cea634f6d9d674816f6553506cbff6f018fb10298a685315bd512f68834ac83abe1d139549e335d5dffdbb398decd9edf4ceecbb8c1ab88946114b517876be
data/.gitignore CHANGED
@@ -37,3 +37,5 @@
37
37
  .rvmrc
38
38
 
39
39
  .idea
40
+
41
+ Gemfile.lock
data/CHANGELOG.md CHANGED
@@ -7,6 +7,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
7
7
 
8
8
  ## UNRELEASED
9
9
 
10
+ ## [0.1.0] - 2022-07-20
11
+ - Added `exit_on_signal` to exit instead of raising a `SignalException`. Fixes #1.
12
+
10
13
  ## [0.0.3] - 2020-11-25
11
14
  - Allow to access the executor from outside the signal handler.
12
15
  - Use `require "sigurd"` without having to require files individually.
data/README.md CHANGED
@@ -81,6 +81,13 @@ backoff to wait before restarting it. You can instead use the `sleep_seconds`
81
81
  setting to always sleep a fixed amount of time before retrying. There
82
82
  is no limit to retries.
83
83
 
84
+ ## Configuration
85
+
86
+ By default, sigurd will exit the process when a TERM, KILL or QUIT signal is received. You can change this
87
+ behavior to instead raise the original `SignalException` by setting
88
+
89
+ Sigurd.exit_on_signal = true
90
+
84
91
  ## Contributing
85
92
 
86
93
  Bug reports and pull requests are welcome on GitHub at https://github.com/flipp-oss/sigurd .
@@ -21,10 +21,15 @@ module Sigurd
21
21
  @runner.start
22
22
 
23
23
  loop do
24
- case signal_queue.pop
24
+ signal = signal_queue.pop
25
+ case signal
25
26
  when *SIGNALS
26
27
  @runner.stop
27
- break
28
+ if Sigurd.exit_on_signal
29
+ exit 0
30
+ else
31
+ raise(SignalException, signal)
32
+ end
28
33
  else
29
34
  ready = IO.select([reader, writer])
30
35
 
@@ -41,9 +46,8 @@ module Sigurd
41
46
  # https://stackoverflow.com/questions/29568298/run-code-when-signal-is-sent-but-do-not-trap-the-signal-in-ruby
42
47
  def prepend_handler(signal)
43
48
  previous = Signal.trap(signal) do
44
- previous = -> { raise SignalException, signal } unless previous.respond_to?(:call)
45
49
  yield
46
- previous.call
50
+ previous.call if previous&.respond_to?(:call)
47
51
  end
48
52
  end
49
53
 
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Sigurd
4
- VERSION = '0.0.3'
4
+ VERSION = '0.1.0'
5
5
  end
data/lib/sigurd.rb CHANGED
@@ -6,4 +6,9 @@ require 'sigurd/signal_handler'
6
6
 
7
7
  # :nodoc:
8
8
  module Sigurd
9
+
10
+ class << self
11
+ attr_accessor :exit_on_signal
12
+ end
13
+
9
14
  end
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'sigurd/signal_handler'
3
+ require 'sigurd'
4
4
 
5
5
  RSpec.describe Sigurd::SignalHandler do
6
6
  describe '#run!' do
@@ -11,8 +11,22 @@ RSpec.describe Sigurd::SignalHandler do
11
11
  expect(runner).to receive(:stop)
12
12
 
13
13
  signal_handler = described_class.new(runner)
14
- signal_handler.send(:unblock, described_class::SIGNALS.first)
15
- signal_handler.run!
14
+ Thread.new { sleep 1; Process.kill('TERM', 0) }
15
+ expect { signal_handler.run! }.to raise_error(SignalException)
16
16
  end
17
+
18
+ context 'when exit_on_signal is true' do
19
+ it 'should raise a SignalException' do
20
+ Sigurd.exit_on_signal = true
21
+ runner = TestRunners::TestRunner.new
22
+ expect(runner).to receive(:start)
23
+ expect(runner).to receive(:stop)
24
+
25
+ signal_handler = described_class.new(runner)
26
+ Thread.new { sleep 1; Process.kill('TERM', 0) }
27
+ expect { signal_handler.run! }.to raise_error(SystemExit)
28
+ end
29
+ end
30
+
17
31
  end
18
32
  end
data/spec/spec_helper.rb CHANGED
@@ -55,4 +55,8 @@ RSpec.configure do |config|
55
55
  mocks.yield_receiver_to_any_instance_implementation_blocks = true
56
56
  mocks.verify_partial_doubles = true
57
57
  end
58
+
59
+ config.before(:each) do
60
+ Sigurd.exit_on_signal = false
61
+ end
58
62
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sigurd
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Daniel Orner
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-11-25 00:00:00.000000000 Z
11
+ date: 2022-07-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: concurrent-ruby
@@ -153,7 +153,6 @@ files:
153
153
  - CHANGELOG.md
154
154
  - CODE_OF_CONDUCT.md
155
155
  - Gemfile
156
- - Gemfile.lock
157
156
  - Guardfile
158
157
  - LICENSE.md
159
158
  - README.md
data/Gemfile.lock DELETED
@@ -1,103 +0,0 @@
1
- PATH
2
- remote: .
3
- specs:
4
- sigurd (0.0.2)
5
- concurrent-ruby (~> 1)
6
- exponential-backoff
7
-
8
- GEM
9
- remote: https://rubygems.org/
10
- specs:
11
- ast (2.4.0)
12
- coderay (1.1.3)
13
- concurrent-ruby (1.1.6)
14
- diff-lcs (1.3)
15
- exponential-backoff (0.0.4)
16
- ffi (1.13.0)
17
- formatador (0.2.5)
18
- guard (2.16.2)
19
- formatador (>= 0.2.4)
20
- listen (>= 2.7, < 4.0)
21
- lumberjack (>= 1.0.12, < 2.0)
22
- nenv (~> 0.1)
23
- notiffany (~> 0.0)
24
- pry (>= 0.9.12)
25
- shellany (~> 0.0)
26
- thor (>= 0.18.1)
27
- guard-compat (1.2.1)
28
- guard-rspec (4.7.3)
29
- guard (~> 2.1)
30
- guard-compat (~> 1.1)
31
- rspec (>= 2.99.0, < 4.0)
32
- guard-rubocop (1.3.0)
33
- guard (~> 2.0)
34
- rubocop (~> 0.20)
35
- listen (3.2.1)
36
- rb-fsevent (~> 0.10, >= 0.10.3)
37
- rb-inotify (~> 0.9, >= 0.9.10)
38
- lumberjack (1.2.5)
39
- method_source (1.0.0)
40
- nenv (0.3.0)
41
- notiffany (0.1.3)
42
- nenv (~> 0.1)
43
- shellany (~> 0.0)
44
- parallel (1.19.1)
45
- parser (2.7.1.3)
46
- ast (~> 2.4.0)
47
- pry (0.13.1)
48
- coderay (~> 1.1)
49
- method_source (~> 1.0)
50
- rainbow (3.0.0)
51
- rb-fsevent (0.10.4)
52
- rb-inotify (0.10.1)
53
- ffi (~> 1.0)
54
- regexp_parser (1.7.0)
55
- rexml (3.2.4)
56
- rspec (3.9.0)
57
- rspec-core (~> 3.9.0)
58
- rspec-expectations (~> 3.9.0)
59
- rspec-mocks (~> 3.9.0)
60
- rspec-core (3.9.2)
61
- rspec-support (~> 3.9.3)
62
- rspec-expectations (3.9.2)
63
- diff-lcs (>= 1.2.0, < 2.0)
64
- rspec-support (~> 3.9.0)
65
- rspec-mocks (3.9.1)
66
- diff-lcs (>= 1.2.0, < 2.0)
67
- rspec-support (~> 3.9.0)
68
- rspec-support (3.9.3)
69
- rspec_junit_formatter (0.4.1)
70
- rspec-core (>= 2, < 4, != 2.12.0)
71
- rubocop (0.85.0)
72
- parallel (~> 1.10)
73
- parser (>= 2.7.0.1)
74
- rainbow (>= 2.2.2, < 4.0)
75
- regexp_parser (>= 1.7)
76
- rexml
77
- rubocop-ast (>= 0.0.3)
78
- ruby-progressbar (~> 1.7)
79
- unicode-display_width (>= 1.4.0, < 2.0)
80
- rubocop-ast (0.0.3)
81
- parser (>= 2.7.0.1)
82
- rubocop-rspec (1.39.0)
83
- rubocop (>= 0.68.1)
84
- ruby-progressbar (1.10.1)
85
- shellany (0.0.1)
86
- thor (1.0.1)
87
- unicode-display_width (1.7.0)
88
-
89
- PLATFORMS
90
- ruby
91
-
92
- DEPENDENCIES
93
- guard (~> 2)
94
- guard-rspec (~> 4)
95
- guard-rubocop (~> 1)
96
- rspec (~> 3)
97
- rspec_junit_formatter (~> 0.3)
98
- rubocop (~> 0.72)
99
- rubocop-rspec (~> 1.27)
100
- sigurd!
101
-
102
- BUNDLED WITH
103
- 2.1.2