frontkick 0.3.5 → 0.4.1

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: 60f95541b62fdc0a191da6d51f297f809b737f52
4
- data.tar.gz: f4a733e629822159ef9199cc54fbeca4fba221b3
3
+ metadata.gz: 9bc4c44cc031f5977ca8d93417ae56abbd2e6d36
4
+ data.tar.gz: eb941fc286e02a0fe3abf28fe0bc975e5e4da86a
5
5
  SHA512:
6
- metadata.gz: b9d959c6869e3a069aca2b1eb6f5596fb5e919ae0a1a2471ff014af01e25e73c8262181a671e91516a5523f771783eba32189ae2fe322bcc26328b238b0a34b7
7
- data.tar.gz: 85c4a12db6391cbeb5d1fc18d7d1317384d7c64ffe41232bc8c2532b31e36e374cdcc07baa2007708fda1dea86bfd4f5f70d86c9a0194024b9dceb13613256cb
6
+ metadata.gz: a02886dbdc4ac359d9ab8b263ea8a34c0902a7c24a7690c00a2ff65db23b0924c1cd8fe22e31083878a7090640cf44697ae785536edf2a8c125430a872d661bd
7
+ data.tar.gz: 93ef0cc02ea29058914f4fc828b42b672c749f4833187fdb5cf79b3b381f8d75ef024d1cf7f54bf113c08257652c4260f6f8ca5d0e09f00b4ac896d16b4874e9
data/CHANGELOG.md CHANGED
@@ -1,3 +1,17 @@
1
+ # 0.4.1 (2015/08/15)
2
+
3
+ Changes:
4
+
5
+ - :timeout option now raises Frontkick::Timeout
6
+
7
+ Enhancements:
8
+
9
+ - Add :timeout_kill => false option not to kill timeouted process
10
+
11
+ # 0.4.0 (2015/08/15)
12
+
13
+ yanked
14
+
1
15
  # 0.3.5 (2015/08/13)
2
16
 
3
17
  Enhancements:
data/README.md CHANGED
@@ -33,7 +33,11 @@ With frontkick, you can easily get the exit code, STDOUT, and STDERR.
33
33
 
34
34
  ### Timeout Option
35
35
 
36
- Frontkick.exec("sleep 2 && ls /hoge", :timeout => 1)
36
+ Frontkick.exec("sleep 2 && ls /hoge", :timeout => 1) # raises Frontkick::Timeout
37
+
38
+ not to kill timeouted process
39
+
40
+ Frontkick.exec("sleep 2 && ls /hoge", :timeout => 1, :timeout_kill => false) # raises Frontkick::Timeout
37
41
 
38
42
  ### Exclusive Option
39
43
 
@@ -4,13 +4,16 @@ require 'open3'
4
4
  module Frontkick
5
5
  class Command
6
6
  def self.exec(cmd, opts = {})
7
+ opts[:timeout_kill] = true unless opts.has_key?(:timeout_kill) # default: true
8
+
7
9
  stdout, stderr, exit_code, duration = nil
8
10
  stdin, out, err, wait_thr, pid = nil
9
11
 
10
12
  cmd_array = cmd.kind_of?(Array) ? cmd : [cmd]
13
+ command = cmd_array.join(' ')
11
14
  lock_fd = file_lock(opts[:exclusive], opts[:exclusive_blocking]) if opts[:exclusive]
12
15
  begin
13
- timeout(opts[:timeout]) do # nil is for no timeout
16
+ timeout(opts[:timeout], Frontkick::TimeoutLocal) do # nil is for no timeout
14
17
  duration = Benchmark.realtime do
15
18
  stdin, out, err, wait_thr = Open3.popen3(*cmd_array)
16
19
  stdin.close
@@ -21,13 +24,13 @@ module Frontkick
21
24
  process_wait(pid)
22
25
  end
23
26
  end
24
- rescue Timeout::Error => e
25
- Process.kill('SIGINT', pid)
26
- exit_code = wait_thr.value.exitstatus
27
- process_wait(pid)
28
- duration = opts[:timeout]
29
- stdout = ""
30
- stderr = "pid:#{pid}\tcommand:#{cmd_array.join(' ')} is timeout!"
27
+ rescue Frontkick::TimeoutLocal => e
28
+ if opts[:timeout_kill]
29
+ Process.kill('SIGINT', pid)
30
+ exit_code = wait_thr.value.exitstatus
31
+ process_wait(pid)
32
+ end
33
+ raise Frontkick::Timeout.new(pid, command, opts[:timeout_kill])
31
34
  ensure
32
35
  stdin.close if stdin and !stdin.closed?
33
36
  out.close if out and !out.closed?
@@ -1,3 +1,23 @@
1
+ require 'json'
2
+ require 'timeout'
3
+
1
4
  module Frontkick
5
+ # ref. http://docs.ruby-lang.org/ja/1.9.3/class/Timeout=3a=3aError.html
6
+ class TimeoutLocal < ::Timeout::Error; end
2
7
  class Locked < StandardError; end
8
+ class Timeout < StandardError
9
+ attr_reader :pid, :command, :killed
10
+
11
+ def initialize(pid, command, killed)
12
+ @pid = pid
13
+ @command = command
14
+ @killed = killed
15
+ end
16
+
17
+ def to_s
18
+ {pid: @pid, command: @command, killed: @killed}.to_json
19
+ end
20
+
21
+ alias_method :message, :to_s
22
+ end
3
23
  end
@@ -1,3 +1,3 @@
1
1
  module Frontkick
2
- VERSION = "0.3.5"
2
+ VERSION = "0.4.1"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: frontkick
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.5
4
+ version: 0.4.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Naotoshi Seo
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-08-13 00:00:00.000000000 Z
11
+ date: 2015-08-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake