GitHub Sale: sign up for any paid plan this week and pay nothing until January 1, 2009!  [ hide ]

public
Description: Subtlety: SVN => RSS, hAtom => Atom
Homepage: http://subtlety.errtheblog.com/
Clone URL: git://github.com/defunkt/subtlety.git
better timeouts
defunkt (author)
Tue Jan 22 04:48:36 -0800 2008
commit  232e64be0c530da73956d11bd1485d0a55d3b1cc
tree    a06792542b408df874054e1dd48b653c127600da
parent  019d89a77f9be6abed973656076ad2a0d7a2ae2f
...
2
3
4
5
 
6
7
8
...
19
20
21
 
 
 
 
 
 
 
 
 
 
22
23
24
...
41
42
43
44
 
 
45
46
47
...
139
140
141
 
 
142
143
144
145
146
147
 
 
 
148
149
150
151
 
 
 
152
153
154
 
155
156
157
 
 
 
 
158
159
160
...
2
3
4
 
5
6
7
8
...
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
...
51
52
53
 
54
55
56
57
58
...
150
151
152
153
154
155
156
157
158
159
 
160
161
162
163
164
165
 
166
167
168
169
170
 
171
172
173
174
175
176
177
178
179
180
181
0
@@ -2,7 +2,7 @@
0
 # > copyrite 2008 chris wanstrath
0
 # < chris[at]ozmm[dot]org
0
 # > MIT License
0
-%w( rubygems open-uri erb timeout sinatra sequel mofo open3 ).each { |f| require f }
0
+%w( rubygems open-uri erb timeout sinatra sequel mofo open3 open4 ).each { |f| require f }
0
 gem 'mofo', '>= 0.2.11'
0
 Mofo.timeout = 10
0
 
0
@@ -19,6 +19,16 @@ rescue Timeout::Error
0
   nil
0
 end
0
 
0
+def timeout_exec(command)
0
+ pid = nil
0
+ Timeout.timeout(5) do
0
+ pid, _, stdout, _ = Open4.popen4(*command.split(' '))
0
+ stdout.read
0
+ end
0
+rescue Timeout::Error
0
+ Process.kill('HUP', pid)
0
+end
0
+
0
 ##
0
 # DB stuff
0
 DB = Sequel('sqlite:/db/subtle.db')
0
@@ -41,7 +51,8 @@ class Item < Sequel::Model
0
   end
0
 
0
   def self.is_svn?(url)
0
- timeout { `/usr/bin/env svn info #{url}` =~ /Path:/ }
0
+ info = timeout_exec "/usr/bin/env svn info #{url}"
0
+ info =~ /Path:/
0
   end
0
 
0
   def self.find_or_create_by_url(url)
0
@@ -139,22 +150,32 @@ def render_svn_feed(item)
0
   xslt_file = "/tmp/tmp-#{item.key}.xslt"
0
   erb_file = "#{File.expand_path(File.dirname(__FILE__))}/templates/svnlog.erb"
0
 
0
+ cleanup = proc { rm tmp_file, xslt_file }
0
+
0
   File.open(xslt_file, 'w') do |file|
0
     file.puts ERB.new(File.read(erb_file)).result(binding)
0
   end
0
 
0
   File.open(tmp_file, 'w') do |f|
0
- timeout { f.puts `/usr/bin/env svn log #{item.url.gsub(/ |\\|;/,'')} --limit 15 -v --xml` }
0
+ value = timeout_exec "/usr/bin/env svn log #{item.url.gsub(/ |\\|;/,'')} --limit 15 -v --xml"
0
+ return cleanup[] if value.nil?
0
+ f.puts value
0
   end
0
 
0
   File.open(@file, 'w') do |f|
0
- timeout { f.puts `/usr/bin/env xsltproc #{xslt_file} #{tmp_file}` }
0
+ value = timeout_exec "/usr/bin/env xsltproc #{xslt_file} #{tmp_file}"
0
+ return cleanup[] if value.nil?
0
+ f.puts value
0
   end
0
 
0
- `rm #{tmp_file} #{xslt_file}`
0
+ cleanup[]
0
   sendfile @file
0
 end
0
 
0
+def rm(*files)
0
+ `rm #{files.join(' ')}`
0
+end
0
+
0
 def render_atom_feed(item)
0
   website = timeout { open(item.url).read }
0
   title = Hpricot(website).at(:title).innerHTML

Comments

    No one has commented yet.