procession 0.0.1
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.
- data/Gemfile +3 -0
- data/README.md +3 -0
- data/lib/procession/process.rb +70 -0
- data/lib/procession/version.rb +3 -0
- data/lib/procession.rb +7 -0
- data/procession.gemspec +27 -0
- data/spec/procession/example_app.rb +5 -0
- data/spec/procession/procession_spec.rb +42 -0
- metadata +101 -0
data/Gemfile
ADDED
data/README.md
ADDED
@@ -0,0 +1,70 @@
|
|
1
|
+
require 'childprocess'
|
2
|
+
|
3
|
+
module Procession
|
4
|
+
class Process
|
5
|
+
def initialize(options)
|
6
|
+
@command = options.delete(:command)
|
7
|
+
@await = options.delete(:await)
|
8
|
+
@working_dir = options.delete(:working_dir)
|
9
|
+
@environment = options.delete(:environment)
|
10
|
+
end
|
11
|
+
|
12
|
+
def start
|
13
|
+
args = @command.split(' ')
|
14
|
+
@proc = ChildProcess.build(*args)
|
15
|
+
|
16
|
+
setup_cwd
|
17
|
+
setup_environment
|
18
|
+
|
19
|
+
r, w = IO.pipe
|
20
|
+
|
21
|
+
@proc.io.stdout = @proc.io.stderr = w
|
22
|
+
|
23
|
+
@proc.start
|
24
|
+
w.close
|
25
|
+
|
26
|
+
all_output = ""
|
27
|
+
|
28
|
+
begin
|
29
|
+
started = false
|
30
|
+
until started
|
31
|
+
partial = r.readpartial(8192)
|
32
|
+
puts partial if ENV['CAPPIE_DEBUG']
|
33
|
+
all_output << partial
|
34
|
+
if (all_output =~ @await)
|
35
|
+
started = true
|
36
|
+
end
|
37
|
+
end
|
38
|
+
rescue EOFError
|
39
|
+
raise ProcessExitedError.new "The app process exited\nSTDOUT:\n#{all_output}"
|
40
|
+
end
|
41
|
+
|
42
|
+
Thread.new do
|
43
|
+
while true
|
44
|
+
partial = r.readpartial(8192)
|
45
|
+
puts partial if ENV['CAPPIE_DEBUG']
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
at_exit do
|
50
|
+
@proc.stop
|
51
|
+
end
|
52
|
+
|
53
|
+
@proc.io.inherit!
|
54
|
+
|
55
|
+
@proc
|
56
|
+
end
|
57
|
+
|
58
|
+
private
|
59
|
+
|
60
|
+
def setup_environment
|
61
|
+
@environment.each { |key, value| @proc.environment[key] = value } unless @environment.nil?
|
62
|
+
end
|
63
|
+
|
64
|
+
def setup_cwd
|
65
|
+
@proc.cwd = @working_dir unless @working_dir.nil?
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
class ProcessExitedError < RuntimeError; end
|
70
|
+
end
|
data/lib/procession.rb
ADDED
data/procession.gemspec
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$LOAD_PATH.unshift File.expand_path("../lib", __FILE__)
|
3
|
+
require "procession/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.name = 'procession'
|
7
|
+
s.version = Procession::VERSION
|
8
|
+
s.authors = ["Josh Chisholm"]
|
9
|
+
s.email = "josh@featurist.co.uk"
|
10
|
+
s.description = 'Runs a process and blocks until it starts properly'
|
11
|
+
s.summary = "procession-#{s.version}"
|
12
|
+
s.homepage = "http://github.com/featurist/procession"
|
13
|
+
|
14
|
+
s.platform = Gem::Platform::RUBY
|
15
|
+
|
16
|
+
s.add_runtime_dependency 'childprocess', '>= 0.3.8'
|
17
|
+
|
18
|
+
s.add_development_dependency 'rspec-expectations', '>= 2.0.1'
|
19
|
+
s.add_development_dependency 'rack', '>= 1.5.2'
|
20
|
+
|
21
|
+
s.rubygems_version = ">= 1.6.1"
|
22
|
+
s.files = `git ls-files`.split("\n").reject {|path| path =~ /\.gitignore$/ }
|
23
|
+
s.test_files = `git ls-files -- {spec}/*`.split("\n")
|
24
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
25
|
+
s.rdoc_options = ["--charset=UTF-8"]
|
26
|
+
s.require_path = "lib"
|
27
|
+
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
require_relative '../../lib/procession/process'
|
2
|
+
|
3
|
+
module Procession
|
4
|
+
|
5
|
+
describe Process do
|
6
|
+
|
7
|
+
def example_app_path
|
8
|
+
File.join(File.dirname(__FILE__), "example_app.rb")
|
9
|
+
end
|
10
|
+
|
11
|
+
it 'runs a process and awaits some output' do
|
12
|
+
process = Process.new(command: "ruby #{example_app_path}", await: /#{Dir.pwd}/).start
|
13
|
+
process.should be_alive
|
14
|
+
process.stop
|
15
|
+
end
|
16
|
+
|
17
|
+
it 'sets environment variables' do
|
18
|
+
process = Process.new(command: "ruby #{example_app_path}", environment: { FOO: 'omg' }, await: /omg/).start
|
19
|
+
process.should be_alive
|
20
|
+
process.stop
|
21
|
+
end
|
22
|
+
|
23
|
+
it 'accepts a working directory' do
|
24
|
+
dir = File.dirname(__FILE__)
|
25
|
+
Dir.chdir dir do
|
26
|
+
process = Process.new(command: "ruby #{example_app_path}", await: /#{dir}/).start
|
27
|
+
process.should be_alive
|
28
|
+
process.stop
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
describe 'when the process exits' do
|
33
|
+
it 'raises an exception with the stdout output' do
|
34
|
+
lambda {
|
35
|
+
Process.new(command: 'pwd').start
|
36
|
+
}.should raise_error("The app process exited\nSTDOUT:\n#{Dir.pwd}\n")
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
end
|
41
|
+
|
42
|
+
end
|
metadata
ADDED
@@ -0,0 +1,101 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: procession
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Josh Chisholm
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2013-08-28 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: childprocess
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: 0.3.8
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ! '>='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: 0.3.8
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: rspec-expectations
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ! '>='
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: 2.0.1
|
38
|
+
type: :development
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ! '>='
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: 2.0.1
|
46
|
+
- !ruby/object:Gem::Dependency
|
47
|
+
name: rack
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
50
|
+
requirements:
|
51
|
+
- - ! '>='
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: 1.5.2
|
54
|
+
type: :development
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ! '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: 1.5.2
|
62
|
+
description: Runs a process and blocks until it starts properly
|
63
|
+
email: josh@featurist.co.uk
|
64
|
+
executables: []
|
65
|
+
extensions: []
|
66
|
+
extra_rdoc_files: []
|
67
|
+
files:
|
68
|
+
- Gemfile
|
69
|
+
- README.md
|
70
|
+
- lib/procession.rb
|
71
|
+
- lib/procession/process.rb
|
72
|
+
- lib/procession/version.rb
|
73
|
+
- procession.gemspec
|
74
|
+
- spec/procession/example_app.rb
|
75
|
+
- spec/procession/procession_spec.rb
|
76
|
+
homepage: http://github.com/featurist/procession
|
77
|
+
licenses: []
|
78
|
+
post_install_message:
|
79
|
+
rdoc_options:
|
80
|
+
- --charset=UTF-8
|
81
|
+
require_paths:
|
82
|
+
- lib
|
83
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
84
|
+
none: false
|
85
|
+
requirements:
|
86
|
+
- - ! '>='
|
87
|
+
- !ruby/object:Gem::Version
|
88
|
+
version: '0'
|
89
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
90
|
+
none: false
|
91
|
+
requirements:
|
92
|
+
- - ! '>='
|
93
|
+
- !ruby/object:Gem::Version
|
94
|
+
version: '0'
|
95
|
+
requirements: []
|
96
|
+
rubyforge_project:
|
97
|
+
rubygems_version: 1.8.24
|
98
|
+
signing_key:
|
99
|
+
specification_version: 3
|
100
|
+
summary: procession-0.0.1
|
101
|
+
test_files: []
|