runnerbean 0.0.2 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/examples/ensure_started +18 -0
- data/examples/front_and_back +3 -42
- data/examples/process_groups +3 -42
- data/examples/processes/backend.rb +23 -0
- data/examples/processes/frontend.rb +23 -0
- data/examples/processes/my_test_process.rb +21 -0
- data/examples/simple +2 -24
- data/lib/runnerbean/process_group.rb +11 -0
- data/lib/runnerbean/version.rb +1 -1
- data/spec/runnerbean/process_group_spec.rb +20 -19
- data/spec/spec_helper.rb +2 -0
- data/spec/support/process_group_shared_examples.rb +28 -0
- metadata +8 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: eeb3b26430bb762559e9e23c1e282a1c129da954
|
4
|
+
data.tar.gz: 83fd6adbde6f4ff23c4994b53a655b0b923fe9fa
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b890956a793090f1eda8fa49b7dbdd340c391d6806108eafdb1acbb1a0dcf4cc388739024342542a8f6da063a3a21a0f693675b73002739ed79deb0c342b6b47
|
7
|
+
data.tar.gz: 4a30f2bf2f7307257d6caa9995163c08779f4c27bca929a9b5cb16aef830b43440433457c4cf763c4225ea5b39bc564d51ecbd03389f70e4ab0091a40f044d76
|
@@ -0,0 +1,18 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
$LOAD_PATH.unshift(File.expand_path('../lib', __dir__))
|
4
|
+
|
5
|
+
require 'runnerbean'
|
6
|
+
require_relative 'processes/frontend'
|
7
|
+
require_relative 'processes/backend'
|
8
|
+
|
9
|
+
runner = Runnerbean.runner
|
10
|
+
runner.add_process(frontend: Frontend.new,
|
11
|
+
backend: Backend.new)
|
12
|
+
|
13
|
+
smoke_test_group = runner.group(:frontend, :backend)
|
14
|
+
smoke_test_group.name = ('smoke_test')
|
15
|
+
|
16
|
+
smoke_test_group.ensure_started!
|
17
|
+
puts 'combined Frontend and Backend Tests would run here ...'
|
18
|
+
smoke_test_group.kill!
|
data/examples/front_and_back
CHANGED
@@ -1,49 +1,10 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
|
3
|
-
|
4
|
-
$LOAD_PATH.unshift(File.join(APP_ROOT, 'lib'))
|
3
|
+
$LOAD_PATH.unshift(File.expand_path('../lib', __dir__))
|
5
4
|
|
6
5
|
require 'runnerbean'
|
7
|
-
|
8
|
-
|
9
|
-
attr_accessor :group_name
|
10
|
-
|
11
|
-
def start_command
|
12
|
-
"echo 'This would be the Frontend start command'"
|
13
|
-
end
|
14
|
-
|
15
|
-
def sleep_after_start
|
16
|
-
1
|
17
|
-
end
|
18
|
-
|
19
|
-
def kill_command
|
20
|
-
"echo 'This would be the Frontend kill command'"
|
21
|
-
end
|
22
|
-
|
23
|
-
def sleep_after_kill
|
24
|
-
1
|
25
|
-
end
|
26
|
-
end
|
27
|
-
|
28
|
-
class Backend
|
29
|
-
attr_accessor :group_name
|
30
|
-
|
31
|
-
def start_command
|
32
|
-
"echo 'This would be the Backend start command'"
|
33
|
-
end
|
34
|
-
|
35
|
-
def sleep_after_start
|
36
|
-
1
|
37
|
-
end
|
38
|
-
|
39
|
-
def kill_command
|
40
|
-
"echo 'This would be the Backend kill command'"
|
41
|
-
end
|
42
|
-
|
43
|
-
def sleep_after_kill
|
44
|
-
1
|
45
|
-
end
|
46
|
-
end
|
6
|
+
require_relative 'processes/frontend'
|
7
|
+
require_relative 'processes/backend'
|
47
8
|
|
48
9
|
runner = Runnerbean.runner('front_and_back')
|
49
10
|
runner.add_process(frontend: Frontend.new,
|
data/examples/process_groups
CHANGED
@@ -1,49 +1,10 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
|
3
|
-
|
4
|
-
$LOAD_PATH.unshift(File.join(APP_ROOT, 'lib'))
|
3
|
+
$LOAD_PATH.unshift(File.expand_path('../lib', __dir__))
|
5
4
|
|
6
5
|
require 'runnerbean'
|
7
|
-
|
8
|
-
|
9
|
-
attr_accessor :group_name
|
10
|
-
|
11
|
-
def start_command
|
12
|
-
"echo 'This would be the Frontend start command'"
|
13
|
-
end
|
14
|
-
|
15
|
-
def sleep_after_start
|
16
|
-
1
|
17
|
-
end
|
18
|
-
|
19
|
-
def kill_command
|
20
|
-
"echo 'This would be the Frontend kill command'"
|
21
|
-
end
|
22
|
-
|
23
|
-
def sleep_after_kill
|
24
|
-
1
|
25
|
-
end
|
26
|
-
end
|
27
|
-
|
28
|
-
class Backend
|
29
|
-
attr_accessor :group_name
|
30
|
-
|
31
|
-
def start_command
|
32
|
-
"echo 'This would be the Backend start command'"
|
33
|
-
end
|
34
|
-
|
35
|
-
def sleep_after_start
|
36
|
-
1
|
37
|
-
end
|
38
|
-
|
39
|
-
def kill_command
|
40
|
-
"echo 'This would be the Backend kill command'"
|
41
|
-
end
|
42
|
-
|
43
|
-
def sleep_after_kill
|
44
|
-
1
|
45
|
-
end
|
46
|
-
end
|
6
|
+
require_relative 'processes/frontend'
|
7
|
+
require_relative 'processes/backend'
|
47
8
|
|
48
9
|
runner = Runnerbean.runner
|
49
10
|
runner.add_process(frontend: Frontend.new,
|
@@ -0,0 +1,23 @@
|
|
1
|
+
class Backend
|
2
|
+
attr_accessor :group_name
|
3
|
+
|
4
|
+
def start_command
|
5
|
+
"echo 'This would be the Backend start command'"
|
6
|
+
end
|
7
|
+
|
8
|
+
def sleep_after_start
|
9
|
+
1
|
10
|
+
end
|
11
|
+
|
12
|
+
def kill_command
|
13
|
+
"echo 'This would be the Backend kill command'"
|
14
|
+
end
|
15
|
+
|
16
|
+
def sleep_after_kill
|
17
|
+
1
|
18
|
+
end
|
19
|
+
|
20
|
+
def running?
|
21
|
+
false
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
class Frontend
|
2
|
+
attr_accessor :group_name
|
3
|
+
|
4
|
+
def start_command
|
5
|
+
"echo 'This would be the Frontend start command'"
|
6
|
+
end
|
7
|
+
|
8
|
+
def sleep_after_start
|
9
|
+
1
|
10
|
+
end
|
11
|
+
|
12
|
+
def kill_command
|
13
|
+
"echo 'This would be the Frontend kill command'"
|
14
|
+
end
|
15
|
+
|
16
|
+
def sleep_after_kill
|
17
|
+
1
|
18
|
+
end
|
19
|
+
|
20
|
+
def running?
|
21
|
+
true
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
class MyTestProcess
|
2
|
+
attr_accessor :group_name
|
3
|
+
|
4
|
+
def start_command
|
5
|
+
"echo 'This would be the start command, logging to prefix of #{group_name}' &&" \
|
6
|
+
"echo '... with a following delay of #{sleep_after_start}'"
|
7
|
+
end
|
8
|
+
|
9
|
+
def sleep_after_start
|
10
|
+
7
|
11
|
+
end
|
12
|
+
|
13
|
+
def kill_command
|
14
|
+
"echo 'This would be the kill command, logging to prefix of #{group_name}' &&" \
|
15
|
+
"echo '... with a following delay of #{sleep_after_kill}'"
|
16
|
+
end
|
17
|
+
|
18
|
+
def sleep_after_kill
|
19
|
+
4
|
20
|
+
end
|
21
|
+
end
|
data/examples/simple
CHANGED
@@ -1,31 +1,9 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
|
3
|
-
|
4
|
-
$LOAD_PATH.unshift(File.join(APP_ROOT, 'lib'))
|
3
|
+
$LOAD_PATH.unshift(File.expand_path('../lib', __dir__))
|
5
4
|
|
6
5
|
require 'runnerbean'
|
7
|
-
|
8
|
-
class MyTestProcess
|
9
|
-
attr_accessor :group_name
|
10
|
-
|
11
|
-
def start_command
|
12
|
-
"echo 'This would be the start command, logging to prefix of #{group_name}' &&" \
|
13
|
-
"echo '... with a following delay of #{sleep_after_start}'"
|
14
|
-
end
|
15
|
-
|
16
|
-
def sleep_after_start
|
17
|
-
7
|
18
|
-
end
|
19
|
-
|
20
|
-
def kill_command
|
21
|
-
"echo 'This would be the kill command, logging to prefix of #{group_name}' &&" \
|
22
|
-
"echo '... with a following delay of #{sleep_after_kill}'"
|
23
|
-
end
|
24
|
-
|
25
|
-
def sleep_after_kill
|
26
|
-
4
|
27
|
-
end
|
28
|
-
end
|
6
|
+
require_relative 'processes/my_test_process'
|
29
7
|
|
30
8
|
runner = Runnerbean.runner('simple')
|
31
9
|
runner.add_process(my_process: MyTestProcess.new)
|
@@ -19,6 +19,11 @@ module Runnerbean
|
|
19
19
|
@name ||= default_process_group_name
|
20
20
|
end
|
21
21
|
|
22
|
+
def ensure_started!
|
23
|
+
kill_if_running!
|
24
|
+
start!
|
25
|
+
end
|
26
|
+
|
22
27
|
private
|
23
28
|
|
24
29
|
def default_process_group_name
|
@@ -41,6 +46,12 @@ module Runnerbean
|
|
41
46
|
processes.each { |p| p.group_name = name }
|
42
47
|
end
|
43
48
|
|
49
|
+
def kill_if_running!
|
50
|
+
running_processes = processes.select(&:running?)
|
51
|
+
kill_group = self.class.new(*running_processes)
|
52
|
+
kill_group.kill!
|
53
|
+
end
|
54
|
+
|
44
55
|
def find_commands(command)
|
45
56
|
command_getter = "#{command}_command".to_sym
|
46
57
|
processes.map(&command_getter).compact
|
data/lib/runnerbean/version.rb
CHANGED
@@ -55,33 +55,34 @@ module Runnerbean
|
|
55
55
|
describe '#kill!' do
|
56
56
|
subject { group.kill! }
|
57
57
|
|
58
|
-
|
59
|
-
expect(Kernel).to receive(:system).with(the_frontend_kill)
|
60
|
-
subject
|
61
|
-
end
|
62
|
-
|
63
|
-
it 'sleeps for specified time' do
|
64
|
-
expect(Kernel).to receive(:sleep).with(the_frontend.sleep_after_kill)
|
65
|
-
subject
|
66
|
-
end
|
58
|
+
it_behaves_like 'frontend killer'
|
67
59
|
end
|
68
60
|
|
69
61
|
describe '#start!' do
|
70
62
|
subject { group.start! }
|
71
63
|
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
64
|
+
it_behaves_like 'frontend starter'
|
65
|
+
end
|
66
|
+
|
67
|
+
describe '#ensure_started!' do
|
68
|
+
subject { group.ensure_started! }
|
76
69
|
|
77
|
-
|
78
|
-
|
79
|
-
|
70
|
+
context 'when process is not running' do
|
71
|
+
before { allow(the_frontend).to receive(:running?).and_return(false) }
|
72
|
+
|
73
|
+
it 'does not runs kill shell command specified for frontend' do
|
74
|
+
expect(Kernel).to_not receive(:system).with(the_frontend_kill)
|
75
|
+
subject
|
76
|
+
end
|
77
|
+
|
78
|
+
it_behaves_like 'frontend starter'
|
80
79
|
end
|
81
80
|
|
82
|
-
|
83
|
-
|
84
|
-
|
81
|
+
context 'when process is already running' do
|
82
|
+
before { allow(the_frontend).to receive(:running?).and_return(true) }
|
83
|
+
|
84
|
+
it_behaves_like 'frontend killer'
|
85
|
+
it_behaves_like 'frontend starter'
|
85
86
|
end
|
86
87
|
end
|
87
88
|
|
data/spec/spec_helper.rb
CHANGED
@@ -19,6 +19,8 @@
|
|
19
19
|
APP_ROOT = File.expand_path('..', __dir__)
|
20
20
|
$LOAD_PATH.unshift(File.join(APP_ROOT, 'lib'))
|
21
21
|
|
22
|
+
Dir[File.join(APP_ROOT, 'spec/support/**/*.rb')].each(&method(:require))
|
23
|
+
|
22
24
|
# See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
|
23
25
|
RSpec.configure do |config|
|
24
26
|
# rspec-expectations config goes here. You can use an alternate
|
@@ -0,0 +1,28 @@
|
|
1
|
+
shared_examples_for 'frontend starter' do
|
2
|
+
it 'runs shell start command specified for frontend' do
|
3
|
+
expect(Kernel).to receive(:system).with(the_frontend.start_command)
|
4
|
+
subject
|
5
|
+
end
|
6
|
+
|
7
|
+
it 'instructs process to log to logfile, prefixed with group name' do
|
8
|
+
expect(the_frontend).to receive(:group_name=).with(group.name)
|
9
|
+
subject
|
10
|
+
end
|
11
|
+
|
12
|
+
it 'sleeps for specified time after start' do
|
13
|
+
expect(Kernel).to receive(:sleep).with(the_frontend.sleep_after_start)
|
14
|
+
subject
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
shared_examples_for 'frontend killer' do
|
19
|
+
it 'runs kill shell command specified for frontend' do
|
20
|
+
expect(Kernel).to receive(:system).with(the_frontend.kill_command)
|
21
|
+
subject
|
22
|
+
end
|
23
|
+
|
24
|
+
it 'sleeps for specified time after kill' do
|
25
|
+
expect(Kernel).to receive(:sleep).with(the_frontend.sleep_after_kill)
|
26
|
+
subject
|
27
|
+
end
|
28
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: runnerbean
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- baob
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-09-
|
11
|
+
date: 2015-09-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -165,8 +165,12 @@ files:
|
|
165
165
|
- LICENSE.txt
|
166
166
|
- README.md
|
167
167
|
- Rakefile
|
168
|
+
- examples/ensure_started
|
168
169
|
- examples/front_and_back
|
169
170
|
- examples/process_groups
|
171
|
+
- examples/processes/backend.rb
|
172
|
+
- examples/processes/frontend.rb
|
173
|
+
- examples/processes/my_test_process.rb
|
170
174
|
- examples/simple
|
171
175
|
- lib/runnerbean.rb
|
172
176
|
- lib/runnerbean/process_group.rb
|
@@ -178,6 +182,7 @@ files:
|
|
178
182
|
- spec/runnerbean/runner_spec.rb
|
179
183
|
- spec/runnerbean_spec.rb
|
180
184
|
- spec/spec_helper.rb
|
185
|
+
- spec/support/process_group_shared_examples.rb
|
181
186
|
homepage: ''
|
182
187
|
licenses:
|
183
188
|
- MIT
|
@@ -208,3 +213,4 @@ test_files:
|
|
208
213
|
- spec/runnerbean/runner_spec.rb
|
209
214
|
- spec/runnerbean_spec.rb
|
210
215
|
- spec/spec_helper.rb
|
216
|
+
- spec/support/process_group_shared_examples.rb
|