phantom 0.1.0 → 0.2.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/README.md +1 -0
- data/lib/phantom/base.rb +3 -2
- data/lib/phantom/class_methods.rb +3 -2
- data/lib/phantom/version.rb +1 -1
- data/spec/phantom_spec.rb +8 -0
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 80ff1c0ef83038314d47aee7b8fcf85a762a23ca
|
4
|
+
data.tar.gz: b107e2f72ebf43a498abf70d2c5b5aee206668bb
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b90cb1f66bb7ac6e5cb0eaa8a7bf5bfe3a02db8145281e53edf0f6855c09341ef285c7bccda0bb89669a428aa7d7d6eda8c729cf350d8054ada5afce769b3d7c
|
7
|
+
data.tar.gz: ee9dedfe1f696685cbf2797cd877a019be80b38a2036265436c6c6d4c90ebaaa3547fdd1f633e33ef388b1ed2ec80c4920e045bce9581ffd0d9659012ad1006a
|
data/README.md
CHANGED
@@ -37,6 +37,7 @@ rescue Phantom::ForkError => e
|
|
37
37
|
end
|
38
38
|
|
39
39
|
phantom.pid #=> PID or nil if fork fails
|
40
|
+
phantom.name #=> name of the subprocess. The name equals to the name displayed by linux command `ps`.
|
40
41
|
phantom.status #=> 'Alive' | 'Dead' | 'Paused'
|
41
42
|
phantom.dead? #=> true if the sub process is dead (i.e. either ended normally or killed)
|
42
43
|
phantom.alive? #=> true if not dead.
|
data/lib/phantom/base.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
module Phantom
|
2
2
|
|
3
3
|
class << self
|
4
|
-
def run(pid_file: nil, on_ok: nil, on_error: nil, &block)
|
4
|
+
def run(name: 'phantom', pid_file: nil, on_ok: nil, on_error: nil, &block)
|
5
5
|
return Phantom::Base.new(nil) unless block_given?
|
6
6
|
|
7
7
|
raise ForkError.new('Running process exists.', pid_file) if pid_file and File.exist?(pid_file)
|
@@ -10,6 +10,7 @@ module Phantom
|
|
10
10
|
#f = File.new(pid_file, 'w') if pid_file
|
11
11
|
|
12
12
|
pid = fork do
|
13
|
+
$0 = name # Change the subprocess name
|
13
14
|
if pid_file
|
14
15
|
File.open(pid_file, 'w') {|f| f.write Process.pid}
|
15
16
|
end
|
@@ -53,7 +54,7 @@ module Phantom
|
|
53
54
|
end
|
54
55
|
end
|
55
56
|
|
56
|
-
return Phantom::Base.new(pid)
|
57
|
+
return Phantom::Base.new(pid, name)
|
57
58
|
end
|
58
59
|
end
|
59
60
|
end
|
data/lib/phantom/version.rb
CHANGED
data/spec/phantom_spec.rb
CHANGED
@@ -83,4 +83,12 @@ describe Phantom do
|
|
83
83
|
sleep 5
|
84
84
|
File.should_not exist(pid_file)
|
85
85
|
end
|
86
|
+
|
87
|
+
it 'should be able to set process name' do
|
88
|
+
phantom = Phantom.run(name: 'some_bizzare_name') do
|
89
|
+
sleep 5
|
90
|
+
end
|
91
|
+
`ps aux | grep some_bizzare_name`.should_not be_empty
|
92
|
+
phantom.name.should == 'some_bizzare_name'
|
93
|
+
end
|
86
94
|
end
|