bio-commandeer 0.3.0 → 0.4.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/VERSION +1 -1
- data/lib/bio-commandeer/commandeer.rb +14 -3
- data/spec/bio-commandeer_spec.rb +6 -0
- 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: 2b7559a3e351f0efdb098405a03882ea4c535b11
|
4
|
+
data.tar.gz: 443e5ea43b398f5a916bf84fb43225d0ecc7b694
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: '059e8356a0bfdad421f37a69767a7ae3e03379f3adff14a579459665d182daae75e9244e5894fb73aa8140d2902bc13d34a536612cd44fe404ffee96ada82a5e'
|
7
|
+
data.tar.gz: 48e2c1049ed3848e92e37f0c1516eac923774635a27f087245bc0a7451b4e3c1e4aa260a6c9efb534b7df42707a86ef297ff84c3162b09e95992dfa526ca9976
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.4.0
|
@@ -1,4 +1,5 @@
|
|
1
1
|
require 'systemu'
|
2
|
+
require 'timeout'
|
2
3
|
|
3
4
|
module Bio
|
4
5
|
# See #run
|
@@ -9,6 +10,8 @@ module Bio
|
|
9
10
|
# * options is a hash, with keys:
|
10
11
|
# :stdin: a string that is the stdin
|
11
12
|
# :log: if true, turn on logging. If given an object use it as the logger
|
13
|
+
# :timeout: number of seconds to allow the process to run for. If nil (the default),
|
14
|
+
# no timeout.
|
12
15
|
def self.run(command, options={})
|
13
16
|
obj = run_to_finish(command, options)
|
14
17
|
obj.raise_if_failed
|
@@ -34,7 +37,13 @@ module Bio
|
|
34
37
|
end
|
35
38
|
res = CommandResult.new
|
36
39
|
res.command = command
|
37
|
-
|
40
|
+
begin
|
41
|
+
Timeout::timeout(options[:timeout]) do
|
42
|
+
res.status, res.stdout, res.stderr = systemu command, :stdin => options[:stdin]
|
43
|
+
end
|
44
|
+
rescue Timeout::Error => e
|
45
|
+
res.timed_out = true
|
46
|
+
end
|
38
47
|
|
39
48
|
if @log
|
40
49
|
@log.info "Command finished with exitstatus #{res.status.exitstatus}"
|
@@ -44,10 +53,12 @@ module Bio
|
|
44
53
|
end
|
45
54
|
|
46
55
|
class CommandResult
|
47
|
-
attr_accessor :stdout, :stderr, :command, :status
|
56
|
+
attr_accessor :stdout, :stderr, :command, :status, :timed_out
|
48
57
|
|
49
58
|
def raise_if_failed
|
50
|
-
if @
|
59
|
+
if @timed_out
|
60
|
+
raise Bio::CommandFailedException, "Command timed out. Command run was #{command}."
|
61
|
+
elsif @status.exitstatus != 0
|
51
62
|
raise Bio::CommandFailedException, "Command returned non-zero exit status (#{@status.exitstatus}), likely indicating failure. Command run was #{@command} and the STDERR was:\n#{@stderr}\nSTDOUT was: #{@stdout}"
|
52
63
|
end
|
53
64
|
end
|
data/spec/bio-commandeer_spec.rb
CHANGED
@@ -64,4 +64,10 @@ describe "BioCommandeer" do
|
|
64
64
|
obj = Bio::Commandeer.run_to_finish("cat /definitelyNotAFile")
|
65
65
|
expect{obj.raise_if_failed}.to raise_error(Bio::CommandFailedException)
|
66
66
|
end
|
67
|
+
|
68
|
+
it 'should respect timeout' do
|
69
|
+
Bio::Commandeer.run "sleep 2"
|
70
|
+
expect { Bio::Commandeer.run "sleep 1", :timeout => 1}.
|
71
|
+
to raise_error(Bio::CommandFailedException)
|
72
|
+
end
|
67
73
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: bio-commandeer
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ben J. Woodcroft
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-08-
|
11
|
+
date: 2017-08-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bio-logger
|