mediakit 0.0.5 → 0.0.6

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: 739026ab070097e01f9e544c1838bbf532559641
4
- data.tar.gz: bec5a0d43369988119be0a84d1999d781cdc4859
3
+ metadata.gz: 7435ac359f8e6bd85841a8e6d9aa40b4f9984250
4
+ data.tar.gz: f73d0dcf7d9b077eaf702b46844a5f255ca5f94f
5
5
  SHA512:
6
- metadata.gz: 34b726d533096261e10df0dc11c79b737247b4c3eab3b6b6f9d94558e20166574735fd1c83660a0725e350c76c7be4c6129f2509015c4015b3b7866b1ebf2c30
7
- data.tar.gz: aece0527121a414e45f4b46d4efb3ae6610cae4a43e134963d1ba4dc810f5c51565c001a3b0ef7b409706d406ff65ba65a926060f92f1728577750d753b43989
6
+ metadata.gz: 991f5cf8db3564fe37f20a61601318bbf120cf0e66100402850adac03b4cc429fb78ed09ce67cca7e02cfad5c53f3c3da504806c39fb75217e10ffe11a48b520
7
+ data.tar.gz: 66356ffb1faccd86054c39f5680356bc3fadf9e606e3054dd2eb4680e9ebf2a36fa65ff7f8bee8bc69887d31ec6824e9c3adbf312f82c86c032f81e4d07570d4
@@ -32,29 +32,44 @@ module Mediakit
32
32
  command = build_command(bin, *args)
33
33
  exit_status = nil
34
34
  begin
35
- stdin, stdout, stderr, wait_thr = Open3.popen3(command)
35
+ stdin, stdout, stderr, wait_thread = Open3.popen3(command)
36
36
  stdin.close
37
- pid = wait_thr.pid
38
- begin
39
- loop = Coolio::Loop.new
40
- timer, out_watcher, err_watcher = setup_watchers(loop, stdout, stderr)
41
- loop_thread = Thread.new { loop.run }
42
- wait_thr.join
43
- exit_status = (wait_thr.value.exitstatus == 0)
44
- rescue Timeout::Error => error
45
- force_kill_process(pid)
46
- raise(error)
47
- ensure
48
- out_watcher.close unless out_watcher && out_watcher.closed?
49
- err_watcher.close unless err_watcher && err_watcher.closed?
50
- timer.detach if timer
51
- loop_thread.join if loop_thread
52
- end
37
+ output, error_output, exit_status = if @timeout
38
+ wait_with_timeout(stdout, stderr, wait_thread)
39
+ else
40
+ wait_without_timeout(stdout, stderr, wait_thread)
41
+ end
53
42
  rescue Errno::ENOENT => e
54
43
  raise(CommandNotFoundError, "Can't find command - #{command}, #{e.meessage}")
55
44
  end
56
45
 
57
- [out_watcher.data, err_watcher.data, exit_status]
46
+ [output, error_output, exit_status]
47
+ end
48
+
49
+ def wait_without_timeout(stdout, stderr, wait_thread)
50
+ wait_thread.join
51
+ exit_status = (wait_thread.value.exitstatus == 0)
52
+ [stdout.read, stderr.read, exit_status]
53
+ end
54
+
55
+ def wait_with_timeout(stdout, stderr, wait_thread)
56
+ begin
57
+ loop = Coolio::Loop.new
58
+ timer, out_watcher, err_watcher = setup_watchers(loop, stdout, stderr)
59
+ loop_thread = Thread.new { loop.run }
60
+ wait_thread.join
61
+ exit_status = (wait_thread.value.exitstatus == 0)
62
+ rescue Timeout::Error => error
63
+ force_kill_process(wait_thread.pid)
64
+ raise(error)
65
+ ensure
66
+ out_watcher.close if out_watcher && !out_watcher.closed?
67
+ err_watcher.close if err_watcher && !err_watcher.closed?
68
+ timer.detach if timer && timer.attached?
69
+ loop_thread.join if loop_thread
70
+ end
71
+
72
+ [out_watcher.data, err_watcher.data,exit_status]
58
73
  end
59
74
 
60
75
  def build_command(bin, *args)
@@ -1,3 +1,3 @@
1
1
  module Mediakit
2
- VERSION = "0.0.5"
2
+ VERSION = "0.0.6"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mediakit
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.5
4
+ version: 0.0.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - ainame