phantom 0.0.4 → 0.1.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/lib/phantom/class_methods.rb +6 -3
- data/lib/phantom/version.rb +1 -1
- data/spec/base_spec.rb +4 -2
- data/spec/phantom_spec.rb +31 -10
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3843d810f05c3f9159e41ff4f91bdc64a88efd7d
|
4
|
+
data.tar.gz: 688af5a139288b798118b40ae342dca6e6aa1f5a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 062578b6840e9f76f90cdafe086bdf9c03b3656e233b6a95a10d35021c4209b5f69c072fd32bb09a6414ba9fc6315c50fa48a03c3ea66e616ffcf8d4494ca21d
|
7
|
+
data.tar.gz: c9c3d8563f204aed151bdf3e3d79fc9204da82318b6d889e1b122fabeeca22c5f5fe1a854af9be7d28f31f0136a78094bb54249bd92aefea049a6bcf3bc1041b
|
@@ -17,15 +17,18 @@ module Phantom
|
|
17
17
|
at_exit do
|
18
18
|
o.flush
|
19
19
|
o.close
|
20
|
-
|
20
|
+
if pid_file and File.exists? pid_file
|
21
|
+
File.delete pid_file if Process.pid == File.read(pid_file).to_i
|
22
|
+
end
|
21
23
|
end
|
22
24
|
|
23
25
|
i.close
|
24
26
|
begin
|
25
27
|
block.call if block_given?
|
26
28
|
Marshal.dump(Status::OK, o)
|
27
|
-
rescue
|
28
|
-
|
29
|
+
rescue Exception => e
|
30
|
+
status = e.is_a?(SignalException) ? Status::OK : e
|
31
|
+
Marshal.dump(status, o)
|
29
32
|
end
|
30
33
|
end
|
31
34
|
|
data/lib/phantom/version.rb
CHANGED
data/spec/base_spec.rb
CHANGED
@@ -6,6 +6,7 @@ describe Phantom::Base do
|
|
6
6
|
|
7
7
|
after(:each) do
|
8
8
|
File.delete count_file if File.exists? count_file
|
9
|
+
@error = nil
|
9
10
|
end
|
10
11
|
|
11
12
|
it 'should kill the process when called on abort' do
|
@@ -19,8 +20,8 @@ describe Phantom::Base do
|
|
19
20
|
phantom.status.should == Phantom::Status::DEAD
|
20
21
|
end
|
21
22
|
|
22
|
-
it 'should
|
23
|
-
phantom = Phantom.run do
|
23
|
+
it 'should kill the process when called on terminate' do
|
24
|
+
phantom = Phantom.run(on_error: lambda{|e| @error = e}) do
|
24
25
|
sleep 3
|
25
26
|
File.new(count_file, 'w').close
|
26
27
|
end
|
@@ -28,6 +29,7 @@ describe Phantom::Base do
|
|
28
29
|
sleep 5
|
29
30
|
File.should_not exist(count_file)
|
30
31
|
phantom.status.should == Phantom::Status::DEAD
|
32
|
+
@error.should be_nil
|
31
33
|
end
|
32
34
|
|
33
35
|
it 'should be able to pause and to resume the process' do
|
data/spec/phantom_spec.rb
CHANGED
@@ -2,9 +2,13 @@ require 'phantom'
|
|
2
2
|
|
3
3
|
describe Phantom do
|
4
4
|
pid_file = 'tmp/phantom.pid'
|
5
|
+
sub_pid_file = 'tmp/sub.pid'
|
5
6
|
|
6
7
|
after(:each) do
|
7
|
-
|
8
|
+
[pid_file, sub_pid_file].each do |file|
|
9
|
+
File.delete file if File.exist? file
|
10
|
+
end
|
11
|
+
@error = nil
|
8
12
|
end
|
9
13
|
|
10
14
|
it 'should remove the pid file when normally ends.' do
|
@@ -26,26 +30,23 @@ describe Phantom do
|
|
26
30
|
|
27
31
|
it 'should call on_ok when sub processed normally ends' do
|
28
32
|
i = 0
|
29
|
-
|
30
|
-
Phantom.run(pid_file: pid_file, on_ok: lambda{i += 1}, on_error: lambda{|e| err = e}) do
|
33
|
+
Phantom.run(pid_file: pid_file, on_ok: lambda{i += 1}, on_error: lambda{|e| @error = e}) do
|
31
34
|
end
|
32
35
|
sleep 3
|
33
36
|
i.should == 1
|
34
|
-
|
37
|
+
@error.should be_nil
|
35
38
|
end
|
36
39
|
|
37
40
|
it 'should call on_error when sub process raises an unhandled error' do
|
38
|
-
err = nil
|
39
41
|
i = 0
|
40
|
-
Phantom.run(pid_file: pid_file, on_ok: lambda{i += 1}, on_error: lambda{|e|
|
41
|
-
raise
|
42
|
+
Phantom.run(pid_file: pid_file, on_ok: lambda{i += 1}, on_error: lambda{|e| @error = e}) do
|
43
|
+
raise SyntaxError
|
42
44
|
i += 1
|
43
45
|
end
|
44
46
|
|
45
47
|
sleep 3
|
46
48
|
|
47
|
-
|
48
|
-
err.message.should == 'Wa ha ha!'
|
49
|
+
@error.should be_a(SyntaxError)
|
49
50
|
i.should == 0
|
50
51
|
end
|
51
52
|
|
@@ -55,11 +56,31 @@ describe Phantom do
|
|
55
56
|
|
56
57
|
it 'should return a Phantom::Base instance when run' do
|
57
58
|
phantom = Phantom.run do end
|
58
|
-
phantom.should
|
59
|
+
phantom.should be_a(Phantom::Base)
|
59
60
|
end
|
60
61
|
|
61
62
|
it 'should do nothing if block is not given' do
|
62
63
|
phantom = Phantom.run
|
63
64
|
phantom.pid.should be_nil
|
64
65
|
end
|
66
|
+
|
67
|
+
it 'should not call on_error if sub process calls exit' do
|
68
|
+
Phantom.run(on_error: lambda{|e| @error = e}) do
|
69
|
+
exit
|
70
|
+
end
|
71
|
+
@error.should be_nil
|
72
|
+
end
|
73
|
+
|
74
|
+
it 'should be able to fork sub-sub processes' do
|
75
|
+
Phantom.run(pid_file: pid_file, on_error: lambda{|e| @error = e}) do
|
76
|
+
Phantom.run(pid_file: sub_pid_file, on_error: lambda{|e| raise e}) do end
|
77
|
+
sleep 5
|
78
|
+
end
|
79
|
+
@error.should be_nil
|
80
|
+
sleep 1
|
81
|
+
File.should exist(pid_file)
|
82
|
+
File.should_not exist(sub_pid_file)
|
83
|
+
sleep 5
|
84
|
+
File.should_not exist(pid_file)
|
85
|
+
end
|
65
86
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: phantom
|
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
|
- Aetherus
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-11-
|
11
|
+
date: 2013-11-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|