childprocess 0.0.1 → 0.0.2

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/Rakefile CHANGED
@@ -31,6 +31,7 @@ Spec::Rake::SpecTask.new(:rcov) do |spec|
31
31
  spec.libs << 'lib' << 'spec'
32
32
  spec.pattern = 'spec/**/*_spec.rb'
33
33
  spec.rcov = true
34
+ spec.rcov_opts = %w[--exclude spec,ruby-debug,/Library/Ruby,.gem --include lib/childprocess]
34
35
  end
35
36
 
36
37
  task :spec => :check_dependencies
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.1
1
+ 0.0.2
@@ -0,0 +1,90 @@
1
+ module ChildProcess
2
+ class AbstractProcess
3
+ attr_reader :exit_code
4
+
5
+ def initialize(args)
6
+ @args = args
7
+ @started = false
8
+ @exit_code = nil
9
+ end
10
+
11
+ #
12
+ # Launch the child process
13
+ #
14
+ # @return [AbstractProcess] self
15
+ #
16
+
17
+ def start
18
+ launch_process
19
+ @started = true
20
+
21
+ self
22
+ end
23
+
24
+ #
25
+ # Forcibly terminate the process, using increasingly harsher methods if possible.
26
+ #
27
+ # @param [Fixnum] timeout (3) Seconds to wait before trying the next method.
28
+ #
29
+
30
+ def stop(timeout = 3)
31
+ raise SubclassResponsibility, "stop"
32
+ end
33
+
34
+ #
35
+ # Did the process exit?
36
+ #
37
+ # @return [Boolean]
38
+ #
39
+
40
+ def exited?
41
+ raise SubclassResponsibility, "exited?"
42
+ end
43
+
44
+ #
45
+ # Is this process running?
46
+ #
47
+
48
+ def alive?
49
+ started? && !exited?
50
+ end
51
+
52
+ def crashed?
53
+ @exit_code && @exit_code != 0
54
+ end
55
+
56
+ def poll_for_exit(timeout)
57
+ log "polling #{timeout} seconds for exit"
58
+
59
+ end_time = Time.now + timeout
60
+ until (ok = exited?) || Time.now > end_time
61
+ sleep POLL_INTERVAL
62
+ end
63
+
64
+ unless ok
65
+ raise TimeoutError, "process still alive after #{timeout} seconds"
66
+ end
67
+ end
68
+
69
+ private
70
+
71
+ def launch_process
72
+ raise SubclassResponsibility, "launch_process"
73
+ end
74
+
75
+ POLL_INTERVAL = 0.1
76
+
77
+ def started?
78
+ @started
79
+ end
80
+
81
+ def log(*args)
82
+ $stderr.puts "#{self.inspect} : #{args.inspect}" if $DEBUG
83
+ end
84
+
85
+ def assert_started
86
+ raise Error, "process not started" unless started?
87
+ end
88
+
89
+ end # AbstractProcess
90
+ end # ChildProcess
@@ -0,0 +1,5 @@
1
+ module ChildProcess
2
+ class Error < StandardError; end
3
+ class TimeoutError < StandardError; end
4
+ class SubclassResponsibility < StandardError; end
5
+ end
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 0
8
- - 1
9
- version: 0.0.1
8
+ - 2
9
+ version: 0.0.2
10
10
  platform: ruby
11
11
  authors:
12
12
  - Jari Bakken
@@ -74,6 +74,8 @@ files:
74
74
  - Rakefile
75
75
  - VERSION
76
76
  - lib/childprocess.rb
77
+ - lib/childprocess/abstract_process.rb
78
+ - lib/childprocess/errors.rb
77
79
  - lib/childprocess/ironruby.rb
78
80
  - lib/childprocess/ironruby/process.rb
79
81
  - lib/childprocess/jruby.rb