frontkick 0.3.5 → 0.4.1
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/CHANGELOG.md +14 -0
- data/README.md +5 -1
- data/lib/frontkick/command.rb +11 -8
- data/lib/frontkick/error.rb +20 -0
- data/lib/frontkick/version.rb +1 -1
- 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: 9bc4c44cc031f5977ca8d93417ae56abbd2e6d36
|
|
4
|
+
data.tar.gz: eb941fc286e02a0fe3abf28fe0bc975e5e4da86a
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
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
|
|
data/lib/frontkick/command.rb
CHANGED
|
@@ -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
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
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?
|
data/lib/frontkick/error.rb
CHANGED
|
@@ -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
|
data/lib/frontkick/version.rb
CHANGED
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.
|
|
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-
|
|
11
|
+
date: 2015-08-14 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: rake
|