bio-commandeer 0.3.0 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: df4baa9e79d6744596ddb0d4f9549b131698cce6
4
- data.tar.gz: 28b5b0e5f6813c5d61adba3ad0a4b1cda7dac555
3
+ metadata.gz: 2b7559a3e351f0efdb098405a03882ea4c535b11
4
+ data.tar.gz: 443e5ea43b398f5a916bf84fb43225d0ecc7b694
5
5
  SHA512:
6
- metadata.gz: 333ee2f7fc6eb5b5ba24bc31ecc13cf1790e1a99a4e5719f5bdfcfd77617428d8ef071729d8b8ddd004a4bb669e6aaa100a3a2e12ab3cfa788992c81a528d202
7
- data.tar.gz: f94154012f7505943ae437283fb79a37c0eb2a8a629ad6b85b1307b2af10e5bbbfa4847d76890d285d04bb2c9eae1731a6842fcac2d1dceadfeec797987ff4a4
6
+ metadata.gz: '059e8356a0bfdad421f37a69767a7ae3e03379f3adff14a579459665d182daae75e9244e5894fb73aa8140d2902bc13d34a536612cd44fe404ffee96ada82a5e'
7
+ data.tar.gz: 48e2c1049ed3848e92e37f0c1516eac923774635a27f087245bc0a7451b4e3c1e4aa260a6c9efb534b7df42707a86ef297ff84c3162b09e95992dfa526ca9976
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.3.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
- res.status, res.stdout, res.stderr = systemu command, :stdin => options[:stdin]
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 @status.exitstatus != 0
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
@@ -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.3.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-07 00:00:00.000000000 Z
11
+ date: 2017-08-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bio-logger