frontkick 0.5.6 → 0.5.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: 63b7b2198e42097421d10d7239c37e2e54a8dfb3
4
- data.tar.gz: 43d83e3462ef85f1eec58cbf1100444b394b7463
3
+ metadata.gz: 58c67ae20a2f6e7807c0f88329dd758548c5ff3f
4
+ data.tar.gz: 5da56ec31b5550c6cd723f839cf11264844119aa
5
5
  SHA512:
6
- metadata.gz: f745524870d4a7c8a6a99555ef146e9c6bac60b0110d40cf3462b5c7061bddc5087d2daffa8a095c3916517c935f12abfe10680ea493e05b7c35a53d1c0cbcf6
7
- data.tar.gz: 2581b317c4a408e85099b7ee495cb5d8905c4df200d0de74880376b5eec456a1b2775903c713e70818ac2b4c8698f8e30f492c842c5991f0bcad7d512972de18
6
+ metadata.gz: 863d2b04e91a27960ab5fd91c45c54876b71de1852447101f1bd720ea2b47cb6f957be16313088b87483506b788b3a9dc44678e6ad7c429a1685622fe3443d1c
7
+ data.tar.gz: 3ea6eb45338bdf1f42632a098fe32a5e0b1bdfb5859ef49e371c41368b4a8de139832a61128e66949ebb1c4a0e0cffe53c3c3ca167f913239dac06eee70730e1
data/.gitignore CHANGED
@@ -11,3 +11,4 @@ doc/*
11
11
  tmp/*
12
12
  .yardoc
13
13
  pkg
14
+ /.idea/
@@ -1,3 +1,9 @@
1
+ # 0.5.7 (2017/12/25)
2
+
3
+ Enhancements:
4
+
5
+ - Add `timeout_kill_signal` option to set the signal to send on timeout (thanks to niku4i)
6
+
1
7
  # 0.5.6 (2017/04/10)
2
8
 
3
9
  Fixes:
data/README.md CHANGED
@@ -70,16 +70,16 @@ ruby
70
70
  └─ echo
71
71
  ```
72
72
 
73
- NOTE: This interface is different with Kernel.spawn or Open3.popen3, but similar to IO.popen. Kernel.spawn or Open3.popen3 works with no shell if multiple arguments are given:
73
+ NOTE: This **no shell** interface is similar to IO.popen which work as:
74
74
 
75
75
  ```
76
- spawn('echo', '*')
76
+ IO.popen(['echo', '*'])
77
77
  ```
78
78
 
79
- IO.popen works with no shell if an array argument is given:
79
+ but different with Kernel.spawn, or Open3.popen3 which work as:
80
80
 
81
81
  ```
82
- IO.popen(['echo', '*'])
82
+ spawn('echo', '*')
83
83
  ```
84
84
 
85
85
  ### Environment Variables
@@ -93,20 +93,27 @@ result = Frontkick.exec({"FOO"=>"BAR"}, ["echo", "*"])
93
93
  ### Dry Run Option
94
94
 
95
95
  ```ruby
96
- result = Frontkick.exec(["echo", "*"], :dry_run => true)
96
+ result = Frontkick.exec(["echo", "*"], dry_run: true)
97
97
  puts result.stdout #=> echo \*
98
98
  ```
99
99
 
100
100
  ### Timeout Option
101
101
 
102
102
  ```ruby
103
- Frontkick.exec("sleep 2 && ls /hoge", :timeout => 1) # raises Frontkick::Timeout
103
+ Frontkick.exec("sleep 2 && ls /hoge", timeout: 1) # raises Frontkick::Timeout
104
+ ```
105
+
106
+ The default signal that is sent to the command is `SIGINT`.
107
+ You can change the signal as below.
108
+
109
+ ```ruby
110
+ Frontkick.exec("sleep 2 && ls /hoge", timeout: 1, timeout_kill_signal: 'SIGTERM') # raises Frontkick::Timeout
104
111
  ```
105
112
 
106
113
  not to kill timeouted process
107
114
 
108
115
  ```ruby
109
- Frontkick.exec("sleep 2 && ls /hoge", :timeout => 1, :timeout_kill => false) # raises Frontkick::Timeout
116
+ Frontkick.exec("sleep 2 && ls /hoge", timeout: 1, timeout_kill: false) # raises Frontkick::Timeout
110
117
  ```
111
118
 
112
119
  ### Exclusive Option
@@ -114,19 +121,19 @@ Frontkick.exec("sleep 2 && ls /hoge", :timeout => 1, :timeout_kill => false) # r
114
121
  Prohibit another process to run a command concurrently
115
122
 
116
123
  ```ruby
117
- Frontkick.exec("sleep 2 && ls /hoge", :exclusive => "/tmp/frontkick.lock") # raises Fontkick::Locked if locked
124
+ Frontkick.exec("sleep 2 && ls /hoge", exclusive: "/tmp/frontkick.lock") # raises Fontkick::Locked if locked
118
125
  ```
119
126
 
120
127
  If you prefer to be blocked:
121
128
 
122
129
  ```ruby
123
- Frontkick.exec("sleep 2 && ls /hoge", :exclusive => "/tmp/frontkick.lock", :exclusive_blocking => true)
130
+ Frontkick.exec("sleep 2 && ls /hoge", exclusive: "/tmp/frontkick.lock", exclusive_blocking: true)
124
131
  ```
125
132
 
126
133
  ### Redirect Options (:out and :err)
127
134
 
128
135
  ```ruby
129
- Frontkick.exec(["ls /something_not_found"], :out => 'stdout.txt', :err => 'stderr.txt')
136
+ Frontkick.exec(["ls /something_not_found"], out: 'stdout.txt', err: 'stderr.txt')
130
137
  ```
131
138
 
132
139
  This redirects STDOUT and STDERR into files. In this case, result.stdout, and result.stderr are the given filename.
@@ -134,7 +141,7 @@ This redirects STDOUT and STDERR into files. In this case, result.stdout, and re
134
141
  ```ruby
135
142
  out = File.open('stdout.txt', 'w').tap {|fp| fp.sync = true }
136
143
  err = File.open('stderr.txt', 'w').tap {|fp| fp.sync = true }
137
- Frontkick.exec(["ls /something_not_found"], :out => out, :err => err)
144
+ Frontkick.exec(["ls /something_not_found"], out: out, err: err)
138
145
  ```
139
146
 
140
147
  You can also give IO objects. In this case, result.stdout, and result.stderr are the given IO objects.
@@ -142,15 +149,15 @@ You can also give IO objects. In this case, result.stdout, and result.stderr are
142
149
  ### Popen2e Option (Get stdout and stderr together)
143
150
 
144
151
  ```ruby
145
- result = Frontkick.exec("echo foo; ls /something_not_found", :popen2e => true)
152
+ result = Frontkick.exec("echo foo; ls /something_not_found", popen2e: true)
146
153
  puts result.output #=>
147
154
  foo
148
155
  ls: /something_not_found: No such file or directory
149
156
  ```
150
157
 
151
- ### Popen3 Options (such as :chdir)
158
+ ### Other Popen3 Options (such as :chdir)
152
159
 
153
- Other options such as :chdir are treated as options of `Open3.#popen3`.
160
+ Other options such as :chdir are treated as options of `Open3.#popen3` (or `Open3.#popen2e` for the case of `popen2e: true`)
154
161
 
155
162
  ### Kill Child Process
156
163
 
@@ -17,6 +17,7 @@ module Frontkick
17
17
  cmd_array = cmd.is_a?(Array) ? cmd : [cmd]
18
18
 
19
19
  opts[:timeout_kill] = true unless opts.has_key?(:timeout_kill) # default: true
20
+ opts[:timeout_kill_signal] = 'SIGINT' unless opts.has_key?(:timeout_kill_signal) # default: 'SIGINT'
20
21
 
21
22
  exit_code, duration = nil
22
23
  stdin, stdout, stderr, wait_thr, pid = nil
@@ -44,9 +45,8 @@ module Frontkick
44
45
  end
45
46
 
46
47
  if opts[:dry_run]
47
- stdout = env.map {|k,v| "#{k}=#{v} " }.join('')
48
- stdout << "#{cmd_array.first} #{Shellwords.shelljoin(cmd_array[1..-1])}"
49
- return Result.new(:stdout => stdout, :stderr => '', :exit_code => 0, :duration => 0)
48
+ command = build_command(env, cmd_array)
49
+ return Result.new(:stdout => command, :stderr => '', :exit_code => 0, :duration => 0)
50
50
  end
51
51
 
52
52
  popen3_opts = self.popen3_opts(opts)
@@ -105,11 +105,12 @@ module Frontkick
105
105
  end
106
106
  rescue Frontkick::TimeoutLocal => e
107
107
  if opts[:timeout_kill]
108
- Process.kill('SIGINT', pid)
108
+ Process.kill(opts[:timeout_kill_signal], pid)
109
109
  exit_code = wait_thr.value.exitstatus
110
110
  process_wait(pid)
111
111
  end
112
- raise Frontkick::Timeout.new(pid, Shellwords.shelljoin(cmd_array), opts[:timeout_kill])
112
+ command = build_command(env, cmd_array)
113
+ raise Frontkick::Timeout.new(pid, command, opts[:timeout_kill])
113
114
  ensure
114
115
  stdin.close if stdin and !stdin.closed?
115
116
  stdout.close if stdout and !stdout.closed?
@@ -133,9 +134,17 @@ module Frontkick
133
134
 
134
135
  # private
135
136
 
137
+ def self.build_command(env, cmd_array)
138
+ command = env.map {|k,v| "#{k}=#{v} " }.join('')
139
+ command << cmd_array.first
140
+ command << " #{cmd_array[1..-1].shelljoin}" if cmd_array.size > 1
141
+ command
142
+ end
143
+
136
144
  def self.popen3_opts(opts)
137
145
  opts.dup.tap {|o|
138
146
  o.delete(:timeout_kill)
147
+ o.delete(:timeout_kill_signal)
139
148
  o.delete(:exclusive)
140
149
  o.delete(:exclusive_blocking)
141
150
  o.delete(:timeout)
@@ -1,3 +1,3 @@
1
1
  module Frontkick
2
- VERSION = "0.5.6"
2
+ VERSION = "0.5.7"
3
3
  end
@@ -3,7 +3,7 @@ require 'spec_helper'
3
3
  RSpec.describe Frontkick::Command do
4
4
  describe '.exec' do
5
5
  describe 'timeout option' do
6
- subject { described_class.exec('sleep 2 && ls /hoge', timeout: 1) }
6
+ subject { described_class.exec('sleep 2 && ls /hoge', timeout: 0.01) }
7
7
  it { expect { subject }.to raise_error Frontkick::Timeout }
8
8
  end
9
9
  end
@@ -8,6 +8,5 @@ Dir[File.expand_path("support/**/*.rb", ROOT)].each {|f| require f }
8
8
  require 'frontkick'
9
9
 
10
10
  RSpec.configure do |config|
11
- config.treat_symbols_as_metadata_keys_with_true_values = true
12
11
  config.run_all_when_everything_filtered = true
13
12
  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.5.6
4
+ version: 0.5.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: 2017-04-10 00:00:00.000000000 Z
11
+ date: 2017-12-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake
@@ -108,7 +108,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
108
108
  version: '0'
109
109
  requirements: []
110
110
  rubyforge_project:
111
- rubygems_version: 2.4.5
111
+ rubygems_version: 2.6.13
112
112
  signing_key:
113
113
  specification_version: 4
114
114
  summary: Execute a command simply!