frontkick 0.4.6 → 0.4.7

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: b112f355e7130d374cbe37602fcba01a33d63b48
4
- data.tar.gz: 29951a2c3981fcc6d5cc802894fb8247440a1a63
3
+ metadata.gz: 3c05169903b48aeb4fd103f0f8eeac55b2c0b670
4
+ data.tar.gz: fc7d0c173417b7f3f4c24b0551a35a3b43b7b534
5
5
  SHA512:
6
- metadata.gz: d73e071d663f8494d6beecd12c68bd3d7eb448fa3fff2f848a5f5ab9669dd320c1a0ac178aac26b2f4d7c7bb840342efe167260129d68ffa5d1b72e8aaa06a62
7
- data.tar.gz: be8919c5ffd4aaea0d320ae0c749612b2b5b8477cba5684b4e485c91aca2ccd679e50c9ac69275843cdb6139764935009bc68dba8e910a731b15cd01c62a47a0
6
+ metadata.gz: ea20bd4b9dddee6bb5ab47f43c9334ec0d6ce1cde77a9b6660110ce32351a6bf31f699dd72e5d5d757baa964ff0483606082b61131762e489d0da6132f807963
7
+ data.tar.gz: 3cd1984f02b98b548190c0a37843c2ceee42ee79ed89149f036f18f376f519c793fbcf0675c028c931b8c015e3883b411804d2a0751f00d2fe3cf8aa9e89782d
data/CHANGELOG.md CHANGED
@@ -1,3 +1,9 @@
1
+ # 0.4.7 (2016/01/22)
2
+
3
+ Enhancements:
4
+
5
+ - Add kill_child option
6
+
1
7
  # 0.4.6 (2016/01/07)
2
8
 
3
9
  Fixes:
data/README.md CHANGED
@@ -54,6 +54,14 @@ If you prefer to be blocked:
54
54
 
55
55
  Frontkick.exec("sleep 2 && ls /hoge", :exclusive => "/tmp/frontkick.lock", :exclusive_blocking => true)
56
56
 
57
+ ### Kill Child Option
58
+
59
+ On receiving INT and TERM signal, kill the kicked child process before exiting
60
+
61
+ Frontkick.exec("sleep 100", :kill_child => true)
62
+
63
+ NOTE: This uses Kernel.trap inside.
64
+
57
65
  ### Hint: Redirect stderr to stdout
58
66
 
59
67
  Frontkick itself does not aid anything, but you can do as
@@ -0,0 +1,5 @@
1
+ require 'frontkick'
2
+
3
+ puts Process.pid
4
+ result = Frontkick.exec(["sleep 3000"], :kill_child => true)
5
+ puts result.stdout
@@ -26,10 +26,18 @@ module Frontkick
26
26
  err_reader = Thread.new { err.read }
27
27
  stdin.close
28
28
  pid = wait_thr.pid
29
+
30
+ trapped_signal = nil
31
+ if opts[:kill_child]
32
+ trap_signal(pid) {|sig| trapped_signal = sig }
33
+ end
34
+
29
35
  stdout = out_reader.value
30
36
  stderr = err_reader.value
31
37
  exit_code = wait_thr.value.exitstatus
32
38
  process_wait(pid)
39
+
40
+ exit_signal(trapped_signal) if trapped_signal
33
41
  end
34
42
  end
35
43
  rescue Frontkick::TimeoutLocal => e
@@ -50,6 +58,28 @@ module Frontkick
50
58
  Result.new(:stdout => stdout, :stderr => stderr, :exit_code => exit_code, :duration => duration)
51
59
  end
52
60
 
61
+ def self.trap_signal(pid)
62
+ trap :INT do
63
+ Process.kill(:INT, pid)
64
+ yield(:INT)
65
+ end
66
+ trap :TERM do
67
+ Process.kill(:TERM, pid)
68
+ yield(:TERM)
69
+ end
70
+ end
71
+
72
+ def self.exit_signal(signal)
73
+ case signal
74
+ when :INT
75
+ exit(130)
76
+ when :TERM
77
+ exit(143)
78
+ else
79
+ raise 'Non supported signal'
80
+ end
81
+ end
82
+
53
83
  def self.process_wait(pid)
54
84
  begin
55
85
  pid, status = Process.waitpid2(pid) # wait child processes finish
@@ -1,3 +1,3 @@
1
1
  module Frontkick
2
- VERSION = "0.4.6"
2
+ VERSION = "0.4.7"
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.4.6
4
+ version: 0.4.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Naotoshi Seo
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-01-07 00:00:00.000000000 Z
11
+ date: 2016-01-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake
@@ -68,6 +68,7 @@ files:
68
68
  - README.md
69
69
  - Rakefile
70
70
  - example/dry_run.rb
71
+ - example/kill_child.rb
71
72
  - example/run.rb
72
73
  - experiment/capture3_no_deadlock.rb
73
74
  - experiment/cat_63k.rb