right_scraper 1.0.6 → 1.0.7
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.
- data/lib/right_scraper/watcher.rb +26 -15
- data/right_scraper.gemspec +1 -1
- data/spec/svn_scraper_spec.rb +3 -1
- data/spec/watcher_spec.rb +3 -3
- metadata +1 -1
@@ -71,35 +71,46 @@ module RightScale
|
|
71
71
|
# === Return
|
72
72
|
# res(RightScale::WatchStatus):: Outcome of watch, see RightScale::WatchStatus
|
73
73
|
def launch_and_watch(cmd, dest_dir)
|
74
|
-
|
74
|
+
exit_code = nil
|
75
75
|
output = ''
|
76
76
|
|
77
77
|
# Run external process and monitor it in a new thread
|
78
|
-
|
79
|
-
Thread.new do
|
80
|
-
|
81
|
-
|
78
|
+
io = IO.popen(cmd)
|
79
|
+
reader = Thread.new do
|
80
|
+
o = io.read
|
81
|
+
until o == ''
|
82
|
+
output += o
|
83
|
+
o = io.read
|
84
|
+
end
|
85
|
+
Process.wait(io.pid)
|
86
|
+
exit_code = $?.exitstatus
|
82
87
|
end
|
83
88
|
|
84
89
|
# Loop until process is done or times out or takes too much space
|
85
90
|
timed_out = repeat(1, @max_seconds) do
|
86
|
-
output += r.readlines.join
|
87
91
|
if @max_bytes < 0
|
88
|
-
|
92
|
+
exit_code
|
89
93
|
else
|
90
94
|
size = 0
|
91
|
-
Find.find(dest_dir) { |f| size += File.stat(f).size
|
92
|
-
size > @max_bytes ||
|
95
|
+
Find.find(dest_dir) { |f| size += File.stat(f).size rescue 0 if File.file?(f) } if File.directory?(dest_dir)
|
96
|
+
size > @max_bytes || exit_code
|
93
97
|
end
|
94
98
|
end
|
95
99
|
|
96
100
|
# Cleanup and report status
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
101
|
+
# Note: We need to store the exit status before we kill the underlying process so that
|
102
|
+
# if it finished in the mean time we still report -1 as exit code
|
103
|
+
if exit_code
|
104
|
+
exit_status = exit_code
|
105
|
+
outcome = :success
|
106
|
+
else
|
107
|
+
exit_status = -1
|
108
|
+
outcome = (timed_out ? :timeout : :size_exceeded)
|
109
|
+
Process.kill('INT', io.pid)
|
110
|
+
end
|
111
|
+
reader.join
|
112
|
+
io.close
|
113
|
+
res = WatchStatus.new(outcome, exit_status, output)
|
103
114
|
end
|
104
115
|
|
105
116
|
protected
|
data/right_scraper.gemspec
CHANGED
@@ -23,7 +23,7 @@ require 'rubygems'
|
|
23
23
|
|
24
24
|
spec = Gem::Specification.new do |spec|
|
25
25
|
spec.name = 'right_scraper'
|
26
|
-
spec.version = '1.0.
|
26
|
+
spec.version = '1.0.7'
|
27
27
|
spec.authors = ['Raphael Simon']
|
28
28
|
spec.email = 'raphael@rightscale.com'
|
29
29
|
spec.homepage = 'https://github.com/rightscale/right_scraper'
|
data/spec/svn_scraper_spec.rb
CHANGED
@@ -66,10 +66,12 @@ describe RightScale::SvnScraper do
|
|
66
66
|
end
|
67
67
|
|
68
68
|
before(:each) do
|
69
|
+
file_prefix = 'file://'
|
70
|
+
file_prefix += '/' if RUBY_PLATFORM =~ /mswin/
|
69
71
|
@scraper = RightScale::SvnScraper.new(@repo_path, max_bytes=1024**2, max_seconds=20)
|
70
72
|
@repo = RightScale::Repository.from_hash(:display_name => 'test repo',
|
71
73
|
:repo_type => :svn,
|
72
|
-
:url => "
|
74
|
+
:url => "#{file_prefix}#{@svn_repo_path}")
|
73
75
|
end
|
74
76
|
|
75
77
|
after(:all) do
|
data/spec/watcher_spec.rb
CHANGED
@@ -45,7 +45,7 @@ describe RightScale::Watcher do
|
|
45
45
|
|
46
46
|
it 'should report timeouts' do
|
47
47
|
watcher = RightScale::Watcher.new(max_bytes=1, max_seconds=2)
|
48
|
-
status = watcher.launch_and_watch('ruby -e "puts 42; sleep
|
48
|
+
status = watcher.launch_and_watch('ruby -e "STDOUT.sync = true; puts 42; sleep 5"', @dest_dir)
|
49
49
|
status.status.should == :timeout
|
50
50
|
status.exit_code.should == -1
|
51
51
|
status.output.should == "42\n"
|
@@ -53,7 +53,7 @@ describe RightScale::Watcher do
|
|
53
53
|
|
54
54
|
it 'should report size exceeded' do
|
55
55
|
watcher = RightScale::Watcher.new(max_bytes=1, max_seconds=5)
|
56
|
-
status = watcher.launch_and_watch("ruby -e 'puts 42; File.open(File.join(\"#{@dest_dir}\", \"test\"), \"w\") { |f| f.puts \"MORE THAN 2 CHARS\" }'", @dest_dir)
|
56
|
+
status = watcher.launch_and_watch("ruby -e 'STDOUT.sync = true; puts 42; File.open(File.join(\"#{@dest_dir}\", \"test\"), \"w\") { |f| f.puts \"MORE THAN 2 CHARS\" }'; sleep 5", @dest_dir)
|
57
57
|
status.status.should == :size_exceeded
|
58
58
|
status.exit_code.should == -1
|
59
59
|
status.output.should == "42\n"
|
@@ -61,7 +61,7 @@ describe RightScale::Watcher do
|
|
61
61
|
|
62
62
|
it 'should allow infinite size and timeout' do
|
63
63
|
watcher = RightScale::Watcher.new(max_bytes=-1, max_seconds=-1)
|
64
|
-
status = watcher.launch_and_watch("ruby -e 'puts 42; File.open(File.join(\"#{@dest_dir}\", \"test\"), \"w\") { |f| f.puts \"MORE THAN 2 CHARS\" };sleep 2'", @dest_dir)
|
64
|
+
status = watcher.launch_and_watch("ruby -e 'STDOUT.sync = true; puts 42; File.open(File.join(\"#{@dest_dir}\", \"test\"), \"w\") { |f| f.puts \"MORE THAN 2 CHARS\" };sleep 2'", @dest_dir)
|
65
65
|
status.status.should == :success
|
66
66
|
status.exit_code.should == 0
|
67
67
|
status.output.should == "42\n"
|