nonnative 1.0.0 → 1.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/Gemfile.lock +1 -1
- data/README.md +7 -7
- data/lib/nonnative.rb +9 -8
- data/lib/nonnative/configuration/object.rb +47 -0
- data/lib/nonnative/configuration/process.rb +12 -0
- data/lib/nonnative/process/pool.rb +41 -0
- data/lib/nonnative/process/port.rb +53 -0
- data/lib/nonnative/process/system.rb +34 -0
- data/lib/nonnative/version.rb +1 -1
- metadata +6 -6
- data/lib/nonnative/configuration.rb +0 -45
- data/lib/nonnative/definition.rb +0 -10
- data/lib/nonnative/port.rb +0 -51
- data/lib/nonnative/process.rb +0 -32
- data/lib/nonnative/process_pool.rb +0 -37
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: eca9151fff87535cc94a77e24cf243a3d0ed4203dc19c1d8bd5a6e31e604521e
|
|
4
|
+
data.tar.gz: 4cf14cbb4df0dca0740406c1667742b171238ace67463f51387464cd5f2cf9cd
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 5b90f1d35bfbd4edb311a308d39d20711b3cf53b03101a554a088cac1719f6b53cc57f629f862dae4bd7063e8be5413b948edb5c952ee929ef971cdfce804d4b
|
|
7
|
+
data.tar.gz: 2df440113fda404d2a140909b8d2b3ae5a37e6c50619f9a6a29e26d5f7cff4abaf84fe7f1e879d5f592d5a353a9281e2612a33c3c28a0227f7658f0153a0d5c6
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
|
@@ -46,15 +46,15 @@ require 'nonnative'
|
|
|
46
46
|
Nonnative.configure do |config|
|
|
47
47
|
config.strategy = :startup or :before or :manual
|
|
48
48
|
|
|
49
|
-
config.
|
|
50
|
-
d.
|
|
49
|
+
config.process do |d|
|
|
50
|
+
d.command = 'features/support/bin/start 12_321'
|
|
51
51
|
d.timeout = 0.5
|
|
52
52
|
d.port = 12_321
|
|
53
53
|
d.file = 'features/logs/12_321.log'
|
|
54
54
|
end
|
|
55
55
|
|
|
56
|
-
config.
|
|
57
|
-
d.
|
|
56
|
+
config.process do |d|
|
|
57
|
+
d.command = 'features/support/bin/start 12_322'
|
|
58
58
|
d.timeout = 0.5
|
|
59
59
|
d.port = 12_322
|
|
60
60
|
d.file = 'features/logs/12_322.log'
|
|
@@ -67,14 +67,14 @@ end
|
|
|
67
67
|
```yaml
|
|
68
68
|
version: 1.0
|
|
69
69
|
strategy: manual
|
|
70
|
-
|
|
70
|
+
processes:
|
|
71
71
|
-
|
|
72
|
-
|
|
72
|
+
command: features/support/bin/start 12_321
|
|
73
73
|
timeout: 5
|
|
74
74
|
port: 12321
|
|
75
75
|
file: features/logs/12_321.log
|
|
76
76
|
-
|
|
77
|
-
|
|
77
|
+
command: features/support/bin/start 12_322
|
|
78
78
|
timeout: 5
|
|
79
79
|
port: 12322
|
|
80
80
|
file: features/logs/12_322.log
|
data/lib/nonnative.rb
CHANGED
|
@@ -2,14 +2,15 @@
|
|
|
2
2
|
|
|
3
3
|
require 'socket'
|
|
4
4
|
require 'timeout'
|
|
5
|
+
require 'yaml'
|
|
5
6
|
|
|
6
7
|
require 'nonnative/version'
|
|
7
8
|
require 'nonnative/error'
|
|
8
|
-
require 'nonnative/configuration'
|
|
9
|
-
require 'nonnative/
|
|
10
|
-
require 'nonnative/process'
|
|
11
|
-
require 'nonnative/
|
|
12
|
-
require 'nonnative/port'
|
|
9
|
+
require 'nonnative/configuration/object'
|
|
10
|
+
require 'nonnative/configuration/process'
|
|
11
|
+
require 'nonnative/process/system'
|
|
12
|
+
require 'nonnative/process/pool'
|
|
13
|
+
require 'nonnative/process/port'
|
|
13
14
|
require 'nonnative/logger'
|
|
14
15
|
|
|
15
16
|
module Nonnative
|
|
@@ -19,11 +20,11 @@ module Nonnative
|
|
|
19
20
|
end
|
|
20
21
|
|
|
21
22
|
def load_configuration(path)
|
|
22
|
-
@configuration ||= Nonnative::Configuration.load_file(path) # rubocop:disable Naming/MemoizedInstanceVariableName
|
|
23
|
+
@configuration ||= Nonnative::Configuration::Object.load_file(path) # rubocop:disable Naming/MemoizedInstanceVariableName
|
|
23
24
|
end
|
|
24
25
|
|
|
25
26
|
def configuration
|
|
26
|
-
@configuration ||=
|
|
27
|
+
@configuration ||= NNonnative::Configuration::Object.new
|
|
27
28
|
end
|
|
28
29
|
|
|
29
30
|
def configure
|
|
@@ -33,7 +34,7 @@ module Nonnative
|
|
|
33
34
|
end
|
|
34
35
|
|
|
35
36
|
def start
|
|
36
|
-
@process_pool ||= Nonnative::
|
|
37
|
+
@process_pool ||= Nonnative::Process::Pool.new(configuration)
|
|
37
38
|
|
|
38
39
|
@process_pool.start do |pid, result|
|
|
39
40
|
logger.error('Process has started though did respond in time', pid: pid) unless result
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Nonnative
|
|
4
|
+
module Configuration
|
|
5
|
+
class Object
|
|
6
|
+
class << self
|
|
7
|
+
def load_file(path)
|
|
8
|
+
file = YAML.load_file(path)
|
|
9
|
+
|
|
10
|
+
new.tap do |c|
|
|
11
|
+
c.strategy = file['strategy']
|
|
12
|
+
|
|
13
|
+
processes(file, c)
|
|
14
|
+
end
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
private
|
|
18
|
+
|
|
19
|
+
def processes(file, config)
|
|
20
|
+
file['processes'].each do |fd|
|
|
21
|
+
config.process do |d|
|
|
22
|
+
d.command = fd['command']
|
|
23
|
+
d.timeout = fd['timeout']
|
|
24
|
+
d.port = fd['port']
|
|
25
|
+
d.file = fd['file']
|
|
26
|
+
end
|
|
27
|
+
end
|
|
28
|
+
end
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
def initialize
|
|
32
|
+
self.strategy = :before
|
|
33
|
+
self.processes = []
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
attr_accessor :strategy
|
|
37
|
+
attr_accessor :processes
|
|
38
|
+
|
|
39
|
+
def process
|
|
40
|
+
process = Nonnative::Configuration::Process.new
|
|
41
|
+
yield process
|
|
42
|
+
|
|
43
|
+
processes << process
|
|
44
|
+
end
|
|
45
|
+
end
|
|
46
|
+
end
|
|
47
|
+
end
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Nonnative
|
|
4
|
+
module Process
|
|
5
|
+
class Pool
|
|
6
|
+
def initialize(configuration)
|
|
7
|
+
@configuration = configuration
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
def start(&block)
|
|
11
|
+
prs = processes.map { |p, _| p.start }
|
|
12
|
+
pos = processes.map { |_, p| Thread.new { p.open? } }.map(&:value)
|
|
13
|
+
|
|
14
|
+
yield_results(prs, pos, &block)
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
def stop(&block)
|
|
18
|
+
prs = processes.map { |p, _| p.stop }
|
|
19
|
+
pos = processes.map { |_, p| Thread.new { p.closed? } }.map(&:value)
|
|
20
|
+
|
|
21
|
+
yield_results(prs, pos, &block)
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
private
|
|
25
|
+
|
|
26
|
+
attr_reader :configuration
|
|
27
|
+
|
|
28
|
+
def processes
|
|
29
|
+
@processes ||= configuration.processes.map do |d|
|
|
30
|
+
[Nonnative::Process::System.new(d), Nonnative::Process::Port.new(d)]
|
|
31
|
+
end
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
def yield_results(prs, pos)
|
|
35
|
+
prs.zip(pos).each do |pid, result|
|
|
36
|
+
yield pid, result
|
|
37
|
+
end
|
|
38
|
+
end
|
|
39
|
+
end
|
|
40
|
+
end
|
|
41
|
+
end
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Nonnative
|
|
4
|
+
module Process
|
|
5
|
+
class Port
|
|
6
|
+
def initialize(process)
|
|
7
|
+
@process = process
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
def open?
|
|
11
|
+
timeout do
|
|
12
|
+
open_socket
|
|
13
|
+
true
|
|
14
|
+
rescue Errno::ECONNREFUSED, Errno::EHOSTUNREACH
|
|
15
|
+
sleep_interval
|
|
16
|
+
retry
|
|
17
|
+
end
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
def closed?
|
|
21
|
+
timeout do
|
|
22
|
+
open_socket
|
|
23
|
+
raise Nonnative::Error
|
|
24
|
+
rescue Nonnative::Error
|
|
25
|
+
sleep_interval
|
|
26
|
+
retry
|
|
27
|
+
rescue Errno::ECONNREFUSED, Errno::EHOSTUNREACH, Errno::ECONNRESET
|
|
28
|
+
true
|
|
29
|
+
end
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
private
|
|
33
|
+
|
|
34
|
+
attr_reader :process
|
|
35
|
+
|
|
36
|
+
def timeout
|
|
37
|
+
Timeout.timeout(process.timeout) do
|
|
38
|
+
yield
|
|
39
|
+
end
|
|
40
|
+
rescue Timeout::Error
|
|
41
|
+
false
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
def open_socket
|
|
45
|
+
TCPSocket.new('127.0.0.1', process.port).close
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
def sleep_interval
|
|
49
|
+
sleep 0.01
|
|
50
|
+
end
|
|
51
|
+
end
|
|
52
|
+
end
|
|
53
|
+
end
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Nonnative
|
|
4
|
+
module Process
|
|
5
|
+
class System
|
|
6
|
+
def initialize(process)
|
|
7
|
+
@process = process
|
|
8
|
+
@started = false
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
def start
|
|
12
|
+
unless started
|
|
13
|
+
@pid = spawn(process.command, %i[out err] => [process.file, 'a'])
|
|
14
|
+
@started = true
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
pid
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
def stop
|
|
21
|
+
raise Nonnative::Error, "Can't stop a process that has not started" unless started
|
|
22
|
+
|
|
23
|
+
::Process.kill('SIGINT', pid)
|
|
24
|
+
@started = false
|
|
25
|
+
|
|
26
|
+
pid
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
private
|
|
30
|
+
|
|
31
|
+
attr_reader :process, :pid, :started
|
|
32
|
+
end
|
|
33
|
+
end
|
|
34
|
+
end
|
data/lib/nonnative/version.rb
CHANGED
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: nonnative
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 1.
|
|
4
|
+
version: 1.1.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Alex Falkowski
|
|
@@ -158,14 +158,14 @@ files:
|
|
|
158
158
|
- bin/setup
|
|
159
159
|
- lib/nonnative.rb
|
|
160
160
|
- lib/nonnative/before.rb
|
|
161
|
-
- lib/nonnative/configuration.rb
|
|
162
|
-
- lib/nonnative/
|
|
161
|
+
- lib/nonnative/configuration/object.rb
|
|
162
|
+
- lib/nonnative/configuration/process.rb
|
|
163
163
|
- lib/nonnative/error.rb
|
|
164
164
|
- lib/nonnative/logger.rb
|
|
165
165
|
- lib/nonnative/manual.rb
|
|
166
|
-
- lib/nonnative/
|
|
167
|
-
- lib/nonnative/process.rb
|
|
168
|
-
- lib/nonnative/
|
|
166
|
+
- lib/nonnative/process/pool.rb
|
|
167
|
+
- lib/nonnative/process/port.rb
|
|
168
|
+
- lib/nonnative/process/system.rb
|
|
169
169
|
- lib/nonnative/startup.rb
|
|
170
170
|
- lib/nonnative/version.rb
|
|
171
171
|
- nonnative.gemspec
|
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
module Nonnative
|
|
4
|
-
class Configuration
|
|
5
|
-
class << self
|
|
6
|
-
def load_file(path)
|
|
7
|
-
file = YAML.load_file(path)
|
|
8
|
-
|
|
9
|
-
new.tap do |c|
|
|
10
|
-
c.strategy = file['strategy']
|
|
11
|
-
|
|
12
|
-
definitions(file, c)
|
|
13
|
-
end
|
|
14
|
-
end
|
|
15
|
-
|
|
16
|
-
private
|
|
17
|
-
|
|
18
|
-
def definitions(file, config)
|
|
19
|
-
file['definitions'].each do |fd|
|
|
20
|
-
config.definition do |d|
|
|
21
|
-
d.process = fd['process']
|
|
22
|
-
d.timeout = fd['timeout']
|
|
23
|
-
d.port = fd['port']
|
|
24
|
-
d.file = fd['file']
|
|
25
|
-
end
|
|
26
|
-
end
|
|
27
|
-
end
|
|
28
|
-
end
|
|
29
|
-
|
|
30
|
-
def initialize
|
|
31
|
-
self.strategy = :before
|
|
32
|
-
self.definitions = []
|
|
33
|
-
end
|
|
34
|
-
|
|
35
|
-
attr_accessor :strategy
|
|
36
|
-
attr_accessor :definitions
|
|
37
|
-
|
|
38
|
-
def definition
|
|
39
|
-
definition = Nonnative::Definition.new
|
|
40
|
-
yield definition
|
|
41
|
-
|
|
42
|
-
definitions << definition
|
|
43
|
-
end
|
|
44
|
-
end
|
|
45
|
-
end
|
data/lib/nonnative/definition.rb
DELETED
data/lib/nonnative/port.rb
DELETED
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
module Nonnative
|
|
4
|
-
class Port
|
|
5
|
-
def initialize(definition)
|
|
6
|
-
@definition = definition
|
|
7
|
-
end
|
|
8
|
-
|
|
9
|
-
def open?
|
|
10
|
-
timeout do
|
|
11
|
-
open_socket
|
|
12
|
-
true
|
|
13
|
-
rescue Errno::ECONNREFUSED, Errno::EHOSTUNREACH
|
|
14
|
-
sleep_interval
|
|
15
|
-
retry
|
|
16
|
-
end
|
|
17
|
-
end
|
|
18
|
-
|
|
19
|
-
def closed?
|
|
20
|
-
timeout do
|
|
21
|
-
open_socket
|
|
22
|
-
raise Nonnative::Error
|
|
23
|
-
rescue Nonnative::Error
|
|
24
|
-
sleep_interval
|
|
25
|
-
retry
|
|
26
|
-
rescue Errno::ECONNREFUSED, Errno::EHOSTUNREACH, Errno::ECONNRESET
|
|
27
|
-
true
|
|
28
|
-
end
|
|
29
|
-
end
|
|
30
|
-
|
|
31
|
-
private
|
|
32
|
-
|
|
33
|
-
attr_reader :definition
|
|
34
|
-
|
|
35
|
-
def timeout
|
|
36
|
-
Timeout.timeout(definition.timeout) do
|
|
37
|
-
yield
|
|
38
|
-
end
|
|
39
|
-
rescue Timeout::Error
|
|
40
|
-
false
|
|
41
|
-
end
|
|
42
|
-
|
|
43
|
-
def open_socket
|
|
44
|
-
TCPSocket.new('127.0.0.1', definition.port).close
|
|
45
|
-
end
|
|
46
|
-
|
|
47
|
-
def sleep_interval
|
|
48
|
-
sleep 0.01
|
|
49
|
-
end
|
|
50
|
-
end
|
|
51
|
-
end
|
data/lib/nonnative/process.rb
DELETED
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
module Nonnative
|
|
4
|
-
class Process
|
|
5
|
-
def initialize(definition)
|
|
6
|
-
@definition = definition
|
|
7
|
-
@started = false
|
|
8
|
-
end
|
|
9
|
-
|
|
10
|
-
def start
|
|
11
|
-
unless started
|
|
12
|
-
@pid = spawn(definition.process, %i[out err] => [definition.file, 'a'])
|
|
13
|
-
@started = true
|
|
14
|
-
end
|
|
15
|
-
|
|
16
|
-
pid
|
|
17
|
-
end
|
|
18
|
-
|
|
19
|
-
def stop
|
|
20
|
-
raise Nonnative::Error, "Can't stop a process that has not started" unless started
|
|
21
|
-
|
|
22
|
-
::Process.kill('SIGINT', pid)
|
|
23
|
-
@started = false
|
|
24
|
-
|
|
25
|
-
pid
|
|
26
|
-
end
|
|
27
|
-
|
|
28
|
-
private
|
|
29
|
-
|
|
30
|
-
attr_reader :definition, :pid, :started
|
|
31
|
-
end
|
|
32
|
-
end
|
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
module Nonnative
|
|
4
|
-
class ProcessPool
|
|
5
|
-
def initialize(configuration)
|
|
6
|
-
@configuration = configuration
|
|
7
|
-
end
|
|
8
|
-
|
|
9
|
-
def start(&block)
|
|
10
|
-
prs = processes.map { |p, _| p.start }
|
|
11
|
-
pos = processes.map { |_, p| Thread.new { p.open? } }.map(&:value)
|
|
12
|
-
|
|
13
|
-
yield_results(prs, pos, &block)
|
|
14
|
-
end
|
|
15
|
-
|
|
16
|
-
def stop(&block)
|
|
17
|
-
prs = processes.map { |p, _| p.stop }
|
|
18
|
-
pos = processes.map { |_, p| Thread.new { p.closed? } }.map(&:value)
|
|
19
|
-
|
|
20
|
-
yield_results(prs, pos, &block)
|
|
21
|
-
end
|
|
22
|
-
|
|
23
|
-
private
|
|
24
|
-
|
|
25
|
-
attr_reader :configuration
|
|
26
|
-
|
|
27
|
-
def processes
|
|
28
|
-
@processes ||= configuration.definitions.map { |d| [Nonnative::Process.new(d), Nonnative::Port.new(d)] }
|
|
29
|
-
end
|
|
30
|
-
|
|
31
|
-
def yield_results(prs, pos)
|
|
32
|
-
prs.zip(pos).each do |pid, result|
|
|
33
|
-
yield pid, result
|
|
34
|
-
end
|
|
35
|
-
end
|
|
36
|
-
end
|
|
37
|
-
end
|