ultravisor 0.0.0.3.g8cf10dc
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +6 -0
- data/.yardopts +1 -0
- data/LICENCE +674 -0
- data/README.md +451 -0
- data/lib/ultravisor.rb +216 -0
- data/lib/ultravisor/child.rb +481 -0
- data/lib/ultravisor/child/call.rb +16 -0
- data/lib/ultravisor/child/call_receiver.rb +13 -0
- data/lib/ultravisor/child/cast.rb +15 -0
- data/lib/ultravisor/child/cast_receiver.rb +10 -0
- data/lib/ultravisor/child/process_cast_call.rb +38 -0
- data/lib/ultravisor/error.rb +24 -0
- data/lib/ultravisor/logging_helpers.rb +32 -0
- data/ultravisor.gemspec +36 -0
- metadata +188 -0
@@ -0,0 +1,16 @@
|
|
1
|
+
class Ultravisor::Child::Call
|
2
|
+
attr_reader :method_name
|
3
|
+
|
4
|
+
def initialize(method_name, args, blk, rv_q, rv_fail)
|
5
|
+
@method_name, @args, @blk, @rv_q, @rv_fail = method_name, args, blk, rv_q, rv_fail
|
6
|
+
end
|
7
|
+
|
8
|
+
def go!(receiver)
|
9
|
+
@rv_q << receiver.__send__(@method_name, *@args, &@blk)
|
10
|
+
@rv_q.close
|
11
|
+
end
|
12
|
+
|
13
|
+
def child_restarted!
|
14
|
+
@rv_q << @rv_fail
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
class Ultravisor::Child::CallReceiver < BasicObject
|
2
|
+
def initialize(&blk)
|
3
|
+
@blk = blk
|
4
|
+
end
|
5
|
+
|
6
|
+
def method_missing(name, *args, &blk)
|
7
|
+
rv_q = ::Queue.new
|
8
|
+
rv_fail = ::Object.new
|
9
|
+
callback = ::Ultravisor::Child::Call.new(name, args, blk, rv_q, rv_fail)
|
10
|
+
@blk.call(callback)
|
11
|
+
rv_q.pop.tap { |rv| ::Kernel.raise ::Ultravisor::ChildRestartedError.new if rv == rv_fail }
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
class Ultravisor::Child::Cast
|
2
|
+
attr_reader :method_name
|
3
|
+
|
4
|
+
def initialize(method_name, args, blk)
|
5
|
+
@method_name, @args, @blk = method_name, args, blk
|
6
|
+
end
|
7
|
+
|
8
|
+
def go!(receiver)
|
9
|
+
receiver.__send__(@method_name, *@args, &@blk)
|
10
|
+
end
|
11
|
+
|
12
|
+
def child_restarted!
|
13
|
+
# Meh
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
module Ultravisor::Child::ProcessCastCall
|
2
|
+
private
|
3
|
+
|
4
|
+
def process_castcall
|
5
|
+
begin
|
6
|
+
loop do
|
7
|
+
item = @ultravisor_child_castcall_queue.pop(true)
|
8
|
+
|
9
|
+
# Queue has been closed, which is a polite way of saying "we're done here"
|
10
|
+
return if item.nil?
|
11
|
+
|
12
|
+
item.go!(self)
|
13
|
+
|
14
|
+
castcall_fd.getc
|
15
|
+
end
|
16
|
+
rescue ThreadError => ex
|
17
|
+
if ex.message != "queue empty"
|
18
|
+
#:nocov:
|
19
|
+
raise
|
20
|
+
#:nocov:
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
def castcall_fd
|
26
|
+
@ultravisor_child_castcall_fd
|
27
|
+
end
|
28
|
+
|
29
|
+
def process_castcall_loop
|
30
|
+
#:nocov:
|
31
|
+
loop do
|
32
|
+
IO.select([castcall_fd], nil, nil)
|
33
|
+
|
34
|
+
process_castcall
|
35
|
+
end
|
36
|
+
#:nocov:
|
37
|
+
end
|
38
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
class Ultravisor
|
2
|
+
# Base class of all Ultravisor-specific errors
|
3
|
+
class Error < StandardError; end
|
4
|
+
|
5
|
+
# Tried to register a child with an ID of a child that already exists
|
6
|
+
class DuplicateChildError < Error; end
|
7
|
+
|
8
|
+
# Tried to call `#run` on an ultravisor that is already running
|
9
|
+
class AlreadyRunningError < Error; end
|
10
|
+
|
11
|
+
# A `child.call.<method>` was interrupted by the child instance runner terminating
|
12
|
+
class ChildRestartedError < Error; end
|
13
|
+
|
14
|
+
# Something was wrong with the Klass/Args/Method (KAM) passed
|
15
|
+
class InvalidKAMError < Error; end
|
16
|
+
|
17
|
+
# A child's restart policy was exceeded, and the Ultravisor should
|
18
|
+
# terminate
|
19
|
+
class BlownRestartPolicyError < Error; end
|
20
|
+
|
21
|
+
# An internal programming error (aka "a bug") caused a violation of thread safety
|
22
|
+
# requirements
|
23
|
+
class ThreadSafetyError < Error; end
|
24
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
class Ultravisor
|
4
|
+
module LoggingHelpers
|
5
|
+
private
|
6
|
+
|
7
|
+
attr_reader :logger
|
8
|
+
|
9
|
+
def log_exception(ex, progname = nil)
|
10
|
+
#:nocov:
|
11
|
+
progname ||= "#{self.class.to_s}##{caller_locations(2, 1).first.label}"
|
12
|
+
|
13
|
+
logger.error(progname) do
|
14
|
+
explanation = if block_given?
|
15
|
+
yield
|
16
|
+
else
|
17
|
+
false
|
18
|
+
end
|
19
|
+
|
20
|
+
(["#{explanation}#{explanation ? ": " : ""}#{ex.message} (#{ex.class})"] + ex.backtrace).join("\n ")
|
21
|
+
end
|
22
|
+
#:nocov:
|
23
|
+
end
|
24
|
+
|
25
|
+
def logloc
|
26
|
+
#:nocov:
|
27
|
+
loc = caller_locations.first
|
28
|
+
"#{self.class}##{loc.label}"
|
29
|
+
#:nocov:
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
data/ultravisor.gemspec
ADDED
@@ -0,0 +1,36 @@
|
|
1
|
+
begin
|
2
|
+
require "git-version-bump"
|
3
|
+
rescue LoadError
|
4
|
+
nil
|
5
|
+
end
|
6
|
+
|
7
|
+
Gem::Specification.new do |s|
|
8
|
+
s.name = "ultravisor"
|
9
|
+
|
10
|
+
s.version = GVB.version rescue "0.0.0.1.NOGVB"
|
11
|
+
s.date = GVB.date rescue Time.now.strftime("%Y-%m-%d")
|
12
|
+
|
13
|
+
s.platform = Gem::Platform::RUBY
|
14
|
+
|
15
|
+
s.summary = "A template gem"
|
16
|
+
|
17
|
+
s.authors = ["Matt Palmer"]
|
18
|
+
s.email = ["theshed+ultravisor@hezmatt.org"]
|
19
|
+
s.homepage = "https://github.com/mpalmer/ultravisor"
|
20
|
+
|
21
|
+
s.files = `git ls-files -z`.split("\0").reject { |f| f =~ /^(G|spec|Rakefile)/ }
|
22
|
+
|
23
|
+
s.required_ruby_version = ">= 2.3.0"
|
24
|
+
|
25
|
+
|
26
|
+
s.add_development_dependency "bundler"
|
27
|
+
s.add_development_dependency "github-release"
|
28
|
+
s.add_development_dependency "guard-rspec"
|
29
|
+
s.add_development_dependency "rake", "~> 10.4", ">= 10.4.2"
|
30
|
+
# Needed for guard
|
31
|
+
s.add_development_dependency "rb-inotify", "~> 0.9"
|
32
|
+
s.add_development_dependency "redcarpet"
|
33
|
+
s.add_development_dependency "rspec"
|
34
|
+
s.add_development_dependency "simplecov"
|
35
|
+
s.add_development_dependency "yard"
|
36
|
+
end
|
metadata
ADDED
@@ -0,0 +1,188 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: ultravisor
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.0.3.g8cf10dc
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Matt Palmer
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2020-06-01 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: github-release
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: guard-rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rake
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '10.4'
|
62
|
+
- - ">="
|
63
|
+
- !ruby/object:Gem::Version
|
64
|
+
version: 10.4.2
|
65
|
+
type: :development
|
66
|
+
prerelease: false
|
67
|
+
version_requirements: !ruby/object:Gem::Requirement
|
68
|
+
requirements:
|
69
|
+
- - "~>"
|
70
|
+
- !ruby/object:Gem::Version
|
71
|
+
version: '10.4'
|
72
|
+
- - ">="
|
73
|
+
- !ruby/object:Gem::Version
|
74
|
+
version: 10.4.2
|
75
|
+
- !ruby/object:Gem::Dependency
|
76
|
+
name: rb-inotify
|
77
|
+
requirement: !ruby/object:Gem::Requirement
|
78
|
+
requirements:
|
79
|
+
- - "~>"
|
80
|
+
- !ruby/object:Gem::Version
|
81
|
+
version: '0.9'
|
82
|
+
type: :development
|
83
|
+
prerelease: false
|
84
|
+
version_requirements: !ruby/object:Gem::Requirement
|
85
|
+
requirements:
|
86
|
+
- - "~>"
|
87
|
+
- !ruby/object:Gem::Version
|
88
|
+
version: '0.9'
|
89
|
+
- !ruby/object:Gem::Dependency
|
90
|
+
name: redcarpet
|
91
|
+
requirement: !ruby/object:Gem::Requirement
|
92
|
+
requirements:
|
93
|
+
- - ">="
|
94
|
+
- !ruby/object:Gem::Version
|
95
|
+
version: '0'
|
96
|
+
type: :development
|
97
|
+
prerelease: false
|
98
|
+
version_requirements: !ruby/object:Gem::Requirement
|
99
|
+
requirements:
|
100
|
+
- - ">="
|
101
|
+
- !ruby/object:Gem::Version
|
102
|
+
version: '0'
|
103
|
+
- !ruby/object:Gem::Dependency
|
104
|
+
name: rspec
|
105
|
+
requirement: !ruby/object:Gem::Requirement
|
106
|
+
requirements:
|
107
|
+
- - ">="
|
108
|
+
- !ruby/object:Gem::Version
|
109
|
+
version: '0'
|
110
|
+
type: :development
|
111
|
+
prerelease: false
|
112
|
+
version_requirements: !ruby/object:Gem::Requirement
|
113
|
+
requirements:
|
114
|
+
- - ">="
|
115
|
+
- !ruby/object:Gem::Version
|
116
|
+
version: '0'
|
117
|
+
- !ruby/object:Gem::Dependency
|
118
|
+
name: simplecov
|
119
|
+
requirement: !ruby/object:Gem::Requirement
|
120
|
+
requirements:
|
121
|
+
- - ">="
|
122
|
+
- !ruby/object:Gem::Version
|
123
|
+
version: '0'
|
124
|
+
type: :development
|
125
|
+
prerelease: false
|
126
|
+
version_requirements: !ruby/object:Gem::Requirement
|
127
|
+
requirements:
|
128
|
+
- - ">="
|
129
|
+
- !ruby/object:Gem::Version
|
130
|
+
version: '0'
|
131
|
+
- !ruby/object:Gem::Dependency
|
132
|
+
name: yard
|
133
|
+
requirement: !ruby/object:Gem::Requirement
|
134
|
+
requirements:
|
135
|
+
- - ">="
|
136
|
+
- !ruby/object:Gem::Version
|
137
|
+
version: '0'
|
138
|
+
type: :development
|
139
|
+
prerelease: false
|
140
|
+
version_requirements: !ruby/object:Gem::Requirement
|
141
|
+
requirements:
|
142
|
+
- - ">="
|
143
|
+
- !ruby/object:Gem::Version
|
144
|
+
version: '0'
|
145
|
+
description:
|
146
|
+
email:
|
147
|
+
- theshed+ultravisor@hezmatt.org
|
148
|
+
executables: []
|
149
|
+
extensions: []
|
150
|
+
extra_rdoc_files: []
|
151
|
+
files:
|
152
|
+
- ".gitignore"
|
153
|
+
- ".yardopts"
|
154
|
+
- LICENCE
|
155
|
+
- README.md
|
156
|
+
- lib/ultravisor.rb
|
157
|
+
- lib/ultravisor/child.rb
|
158
|
+
- lib/ultravisor/child/call.rb
|
159
|
+
- lib/ultravisor/child/call_receiver.rb
|
160
|
+
- lib/ultravisor/child/cast.rb
|
161
|
+
- lib/ultravisor/child/cast_receiver.rb
|
162
|
+
- lib/ultravisor/child/process_cast_call.rb
|
163
|
+
- lib/ultravisor/error.rb
|
164
|
+
- lib/ultravisor/logging_helpers.rb
|
165
|
+
- ultravisor.gemspec
|
166
|
+
homepage: https://github.com/mpalmer/ultravisor
|
167
|
+
licenses: []
|
168
|
+
metadata: {}
|
169
|
+
post_install_message:
|
170
|
+
rdoc_options: []
|
171
|
+
require_paths:
|
172
|
+
- lib
|
173
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
174
|
+
requirements:
|
175
|
+
- - ">="
|
176
|
+
- !ruby/object:Gem::Version
|
177
|
+
version: 2.3.0
|
178
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
179
|
+
requirements:
|
180
|
+
- - ">"
|
181
|
+
- !ruby/object:Gem::Version
|
182
|
+
version: 1.3.1
|
183
|
+
requirements: []
|
184
|
+
rubygems_version: 3.0.3
|
185
|
+
signing_key:
|
186
|
+
specification_version: 4
|
187
|
+
summary: A template gem
|
188
|
+
test_files: []
|