gearmand_control 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/README.markdown +30 -0
- data/lib/gearmand_control/version.rb +3 -0
- data/lib/gearmand_control.rb +58 -0
- data/spec/gearmand_control_spec.rb +49 -0
- metadata +76 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 0b8acdbc56b4bd1bb5c5aac2ea18613c1a94c67b
|
4
|
+
data.tar.gz: fcb0e60e0b742060f82f74c6a3a25ae57c0dafb1
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 196468b61ccca58223a6679f0c7d165c3c1dce7757e5b298838891b068a071bedc13bc2e5897e799749fdb42c93a2c678664f6cac6ee543db140d9fd593a2739
|
7
|
+
data.tar.gz: c798c920422dbc53de5a668acb5740a870fb20d8a55998a949e9cb2e48cb8c5cae1f441fe292dadad50238f9ff912711c48e34c6cfe6e9faf532a96eb17469b8
|
data/README.markdown
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
# GearmandControl
|
2
|
+
|
3
|
+
Control a [gearmand] process with Ruby. In writing Gearman workers and clients, I've found this useful when running integration tests.
|
4
|
+
|
5
|
+
## Example
|
6
|
+
|
7
|
+
```ruby
|
8
|
+
# start gearmand, listening on 4730
|
9
|
+
gearmand = GearmandControl.new
|
10
|
+
gearmand.start
|
11
|
+
|
12
|
+
# attempt to open a TCP connection on localhost:4730
|
13
|
+
# raises GearmandControl::TestFailed if it cannot
|
14
|
+
gearmand.test!
|
15
|
+
|
16
|
+
# get the process's PID
|
17
|
+
gearmand.pid
|
18
|
+
|
19
|
+
# have we started?
|
20
|
+
gearman.started?
|
21
|
+
|
22
|
+
# stop gearmand
|
23
|
+
gearmand.stop
|
24
|
+
```
|
25
|
+
|
26
|
+
## TODO
|
27
|
+
|
28
|
+
- `gearmand` takes a number of options. Make it easy to set those.
|
29
|
+
|
30
|
+
[gearmand]: http://gearman.org/
|
@@ -0,0 +1,58 @@
|
|
1
|
+
require 'socket'
|
2
|
+
require 'timeout'
|
3
|
+
|
4
|
+
class GearmandControl
|
5
|
+
|
6
|
+
UNSTARTED = :unstarted unless defined? UNSTARTED
|
7
|
+
|
8
|
+
class TestFailed < RuntimeError ; end
|
9
|
+
|
10
|
+
attr_reader :address
|
11
|
+
|
12
|
+
def initialize(port)
|
13
|
+
@port = port
|
14
|
+
@command = 'gearmand'
|
15
|
+
@io = UNSTARTED
|
16
|
+
@address = ['localhost', port].join(':')
|
17
|
+
end
|
18
|
+
|
19
|
+
def pid
|
20
|
+
started? ? @io.pid : -1
|
21
|
+
end
|
22
|
+
|
23
|
+
def start
|
24
|
+
process = [@command, '-p', @port]
|
25
|
+
@io = IO.popen(process.map(&method(:String)))
|
26
|
+
end
|
27
|
+
|
28
|
+
def started?
|
29
|
+
@io != UNSTARTED
|
30
|
+
end
|
31
|
+
|
32
|
+
def stop(signal = :TERM)
|
33
|
+
if started?
|
34
|
+
Process.kill(signal, pid)
|
35
|
+
@io.close
|
36
|
+
@io = UNSTARTED
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
def test!
|
41
|
+
socket = nil
|
42
|
+
|
43
|
+
Timeout.timeout(0.5, TestFailed) do
|
44
|
+
begin
|
45
|
+
socket = TCPSocket.new('localhost', 4730)
|
46
|
+
rescue Errno::ECONNREFUSED
|
47
|
+
sleep (rand / 100.0)
|
48
|
+
|
49
|
+
retry
|
50
|
+
ensure
|
51
|
+
socket.close unless socket.nil?
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
true
|
56
|
+
end
|
57
|
+
|
58
|
+
end
|
@@ -0,0 +1,49 @@
|
|
1
|
+
require 'gearmand_control'
|
2
|
+
|
3
|
+
describe GearmandControl do
|
4
|
+
|
5
|
+
before do
|
6
|
+
@control = GearmandControl.new(4730)
|
7
|
+
end
|
8
|
+
|
9
|
+
after do
|
10
|
+
@control.stop
|
11
|
+
end
|
12
|
+
|
13
|
+
it 'starts gearmand' do
|
14
|
+
@control.start
|
15
|
+
|
16
|
+
expect(Process.getsid(@control.pid)).to be_a(Fixnum)
|
17
|
+
end
|
18
|
+
|
19
|
+
it 'stops gearmand' do
|
20
|
+
@control.start
|
21
|
+
pid = @control.pid
|
22
|
+
@control.stop
|
23
|
+
|
24
|
+
expect do
|
25
|
+
Process.getsid(pid)
|
26
|
+
end.to raise_error(Errno::ESRCH)
|
27
|
+
end
|
28
|
+
|
29
|
+
it 'tests succesfully after starting gearmand' do
|
30
|
+
@control.start
|
31
|
+
|
32
|
+
expect do
|
33
|
+
@control.test!
|
34
|
+
end.to_not raise_error
|
35
|
+
end
|
36
|
+
|
37
|
+
it 'raises if its test fails' do
|
38
|
+
expect do
|
39
|
+
@control.test!
|
40
|
+
end.to raise_error(GearmandControl::TestFailed)
|
41
|
+
end
|
42
|
+
|
43
|
+
it 'knows if the daemon has been started' do
|
44
|
+
@control.start
|
45
|
+
|
46
|
+
expect(@control).to be_started
|
47
|
+
end
|
48
|
+
|
49
|
+
end
|
metadata
ADDED
@@ -0,0 +1,76 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: gearmand_control
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Brian
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2013-07-02 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: rspec
|
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
|
+
description: Ruby wrapper around running gearmand
|
42
|
+
email:
|
43
|
+
- bcobb@uwalumni.com
|
44
|
+
executables: []
|
45
|
+
extensions: []
|
46
|
+
extra_rdoc_files: []
|
47
|
+
files:
|
48
|
+
- lib/gearmand_control/version.rb
|
49
|
+
- lib/gearmand_control.rb
|
50
|
+
- README.markdown
|
51
|
+
- spec/gearmand_control_spec.rb
|
52
|
+
homepage: http://github.com/bcobb/gearmand_control
|
53
|
+
licenses: []
|
54
|
+
metadata: {}
|
55
|
+
post_install_message:
|
56
|
+
rdoc_options: []
|
57
|
+
require_paths:
|
58
|
+
- lib
|
59
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
60
|
+
requirements:
|
61
|
+
- - '>='
|
62
|
+
- !ruby/object:Gem::Version
|
63
|
+
version: '0'
|
64
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - '>='
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
requirements: []
|
70
|
+
rubyforge_project:
|
71
|
+
rubygems_version: 2.0.3
|
72
|
+
signing_key:
|
73
|
+
specification_version: 4
|
74
|
+
summary: Control gearmand with Ruby
|
75
|
+
test_files:
|
76
|
+
- spec/gearmand_control_spec.rb
|