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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 3843d810f05c3f9159e41ff4f91bdc64a88efd7d
4
- data.tar.gz: 688af5a139288b798118b40ae342dca6e6aa1f5a
3
+ metadata.gz: 80ff1c0ef83038314d47aee7b8fcf85a762a23ca
4
+ data.tar.gz: b107e2f72ebf43a498abf70d2c5b5aee206668bb
5
5
  SHA512:
6
- metadata.gz: 062578b6840e9f76f90cdafe086bdf9c03b3656e233b6a95a10d35021c4209b5f69c072fd32bb09a6414ba9fc6315c50fa48a03c3ea66e616ffcf8d4494ca21d
7
- data.tar.gz: c9c3d8563f204aed151bdf3e3d79fc9204da82318b6d889e1b122fabeeca22c5f5fe1a854af9be7d28f31f0136a78094bb54249bd92aefea049a6bcf3bc1041b
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.
@@ -1,9 +1,10 @@
1
1
  module Phantom
2
2
  class Base
3
- attr_reader :pid
3
+ attr_reader :pid, :name
4
4
 
5
- def initialize(pid)
5
+ def initialize(pid, name)
6
6
  @pid = pid.nil? ? nil : pid.to_i
7
+ @name = name
7
8
  end
8
9
 
9
10
  def kill(signal)
@@ -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
@@ -1,3 +1,3 @@
1
1
  module Phantom
2
- VERSION = '0.1.0'
2
+ VERSION = '0.2.0'
3
3
  end
@@ -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
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: phantom
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Aetherus