sigurd 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +3 -0
- data/Gemfile.lock +1 -1
- data/README.md +98 -1
- data/lib/sigurd/signal_handler.rb +1 -1
- data/lib/sigurd/version.rb +1 -1
- data/support/flipp-logo.png +0 -0
- metadata +7 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 75efcb785b0d995dae7843c66db4ad72955b2a7d3574af71c41aea634f5f8358
|
4
|
+
data.tar.gz: 4fb1c060a723a5d827fc76bdf23da681904d05ad458dca3653106557d8de4b17
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4c933ceb70894580031de2cd35af38910c9fc896497c0f60e4e4a72d707663c68c80dc6f4c9739bc1cc342080ad6479f3e5855d541c3d3f37516ada1d19b9218
|
7
|
+
data.tar.gz: a5d0795a16a10342e75ee45e8ddf09e5fdbab3ec86d7b1c5e2500dda96e8889f70d5ec1e980c81f8d98df5a230dd906b5de25d8f84b57e3ebffdc9b6e99bb2e1
|
data/CHANGELOG.md
CHANGED
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -1,2 +1,99 @@
|
|
1
1
|
# sigurd
|
2
|
-
Small gem to manage executing looping processes and signal handling
|
2
|
+
Small gem to manage executing looping processes and signal handling.
|
3
|
+
|
4
|
+
<p align="center">
|
5
|
+
<a href="https://badge.fury.io/rb/sigurd"><img src="https://badge.fury.io/rb/sigurd.svg" alt="Gem Version" height="18"></a>
|
6
|
+
<a href="https://codeclimate.com/github/flipp-oss/sigurd/maintainability"><img src="https://api.codeclimate.com/v1/badges/a5fc45a193abadc4e45b/maintainability" /></a>
|
7
|
+
</p>
|
8
|
+
|
9
|
+
# Installation
|
10
|
+
|
11
|
+
Add this line to your application's Gemfile:
|
12
|
+
```ruby
|
13
|
+
gem 'sigurd'
|
14
|
+
```
|
15
|
+
|
16
|
+
And then execute:
|
17
|
+
|
18
|
+
$ bundle
|
19
|
+
|
20
|
+
Or install it yourself as:
|
21
|
+
|
22
|
+
$ gem install sigurd
|
23
|
+
|
24
|
+
# Versioning
|
25
|
+
|
26
|
+
We use a version of semver for this gem. Any change in previous behavior
|
27
|
+
(something works differently or something old no longer works)
|
28
|
+
is denoted with a bump in the minor version (0.4 -> 0.5). Patch versions
|
29
|
+
are for bugfixes or new functionality which does not affect existing code. You
|
30
|
+
should be locking your Gemfile to the minor version:
|
31
|
+
|
32
|
+
```ruby
|
33
|
+
gem 'sigurd', '0.0.1'
|
34
|
+
```
|
35
|
+
|
36
|
+
# Usage
|
37
|
+
|
38
|
+
Sigurd exposes two classes for use with a third class. The ideas is as follows:
|
39
|
+
|
40
|
+
* You have any object which responds to the `start` and `stop` methods.
|
41
|
+
This object is called a "Runner". When the `stop` method is called,
|
42
|
+
the runner should gracefully shut down.
|
43
|
+
* You create an `Executor` class - this manages a thread pool for a
|
44
|
+
list of runners.
|
45
|
+
* You create a `SignalHandler` which is the topmost object. This will
|
46
|
+
handle the signals sent by the system and gracefully forward the
|
47
|
+
requests. You pass the executor into the SignalHandler.
|
48
|
+
* Finally, you call `start` on the `SignalHandler` to begin the execution.
|
49
|
+
|
50
|
+
Sample code:
|
51
|
+
|
52
|
+
```ruby
|
53
|
+
class TestRunner
|
54
|
+
|
55
|
+
def start
|
56
|
+
loop do
|
57
|
+
break if @signal_to_stop
|
58
|
+
# do some logic here
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
def stop
|
63
|
+
@signal_to_stop = true
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
runners = (1..2).map { TestRunner.new }
|
68
|
+
executor = Sigurd::Executor.new(runners, sleep_seconds: 5, logger: Logger.new(STDOUT))
|
69
|
+
Sigurd::SignalHandler.new(executor).run!
|
70
|
+
```
|
71
|
+
|
72
|
+
If you have only a single runner, you can pass it into the `SignalHandler`
|
73
|
+
directly, without using an `Executor`:
|
74
|
+
|
75
|
+
```ruby
|
76
|
+
Sigurd::SignalHandler.new(runner).run!
|
77
|
+
```
|
78
|
+
|
79
|
+
By default, if any of your runners fails, Sigurd will use an exponential
|
80
|
+
backoff to wait before restarting it. You can instead use the `sleep_seconds`
|
81
|
+
setting to always sleep a fixed amount of time before retrying. There
|
82
|
+
is no limit to retries.
|
83
|
+
|
84
|
+
## Contributing
|
85
|
+
|
86
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/flipp-oss/sigurd .
|
87
|
+
|
88
|
+
### Linting
|
89
|
+
|
90
|
+
Sigurd uses Rubocop to lint the code. Please run Rubocop on your code
|
91
|
+
before submitting a PR.
|
92
|
+
|
93
|
+
---
|
94
|
+
<p align="center">
|
95
|
+
Sponsored by<br/>
|
96
|
+
<a href="https://corp.flipp.com/">
|
97
|
+
<img src="support/flipp-logo.png" title="Flipp logo" style="border:none;"/>
|
98
|
+
</a>
|
99
|
+
</p>
|
@@ -35,7 +35,7 @@ module Sigurd
|
|
35
35
|
|
36
36
|
private
|
37
37
|
|
38
|
-
attr_reader :reader, :writer, :signal_queue, :
|
38
|
+
attr_reader :reader, :writer, :signal_queue, :runner
|
39
39
|
|
40
40
|
# https://stackoverflow.com/questions/29568298/run-code-when-signal-is-sent-but-do-not-trap-the-signal-in-ruby
|
41
41
|
def prepend_handler(signal)
|
data/lib/sigurd/version.rb
CHANGED
Binary file
|
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.
|
4
|
+
version: 0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Daniel Orner
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-
|
11
|
+
date: 2020-11-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: concurrent-ruby
|
@@ -136,7 +136,7 @@ dependencies:
|
|
136
136
|
- - "~>"
|
137
137
|
- !ruby/object:Gem::Version
|
138
138
|
version: '1.27'
|
139
|
-
description:
|
139
|
+
description:
|
140
140
|
email:
|
141
141
|
- daniel.orner@flipp.com
|
142
142
|
executables: []
|
@@ -165,11 +165,12 @@ files:
|
|
165
165
|
- spec/executor_spec.rb
|
166
166
|
- spec/signal_handler_spec.rb
|
167
167
|
- spec/spec_helper.rb
|
168
|
+
- support/flipp-logo.png
|
168
169
|
homepage: ''
|
169
170
|
licenses:
|
170
171
|
- Apache-2.0
|
171
172
|
metadata: {}
|
172
|
-
post_install_message:
|
173
|
+
post_install_message:
|
173
174
|
rdoc_options: []
|
174
175
|
require_paths:
|
175
176
|
- lib
|
@@ -185,7 +186,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
185
186
|
version: '0'
|
186
187
|
requirements: []
|
187
188
|
rubygems_version: 3.1.2
|
188
|
-
signing_key:
|
189
|
+
signing_key:
|
189
190
|
specification_version: 4
|
190
191
|
summary: Small gem to manage executing looping processes and signal handling.
|
191
192
|
test_files:
|