Skip to content

Commit

Permalink
capture any error from make and store it into couch if there is a fai…
Browse files Browse the repository at this point in the history
…lure
  • Loading branch information
leafo committed Feb 5, 2012
1 parent 3a5fc9a commit a873011
Showing 1 changed file with 29 additions and 25 deletions.
54 changes: 29 additions & 25 deletions server/bin/make
Expand Up @@ -16,32 +16,36 @@ db = CouchRest.database!(ENV["CLOUDANT_URL"] + "/make")
Dir.mktmpdir do |dir|
Dir.chdir(dir) do
doc = db.get(id)

command = doc["command"]
prefix = doc["prefix"]

File.open("input.tgz", "wb") do |file|
file.print doc.fetch_attachment("input")
end

FileUtils.mkdir_p "input"
FileUtils.mkdir_p prefix

Dir.chdir("input") do
%x{ tar xzf ../input.tgz 2>&1 }
doc["output"] = `#{command}`
db.save_doc(doc)
end

Dir.chdir(prefix) do
%x{ tar czf #{dir}/output.tgz * 2>&1 }
end

begin
doc.put_attachment("output", File.open("#{dir}/output.tgz"))
rescue RestClient::Conflict
# temporarily work around problem with bigcouch
command = doc["command"]
prefix = doc["prefix"]

File.open("input.tgz", "wb") do |file|
file.print doc.fetch_attachment("input")
end

FileUtils.mkdir_p "input"
FileUtils.mkdir_p prefix

Dir.chdir("input") do
%x{ tar xzf ../input.tgz 2>&1 }
doc["output"] = `#{command}`
db.save_doc(doc)
end

Dir.chdir(prefix) do
%x{ tar czf #{dir}/output.tgz * 2>&1 }
end

begin
doc.put_attachment("output", File.open("#{dir}/output.tgz"))
rescue RestClient::Conflict
# temporarily work around problem with bigcouch
end
rescue => err
doc["err"] = err.inspect
doc["err_backtrace"] = err.backtrace.join("\n")
db.save_doc(doc)
end

end
end

0 comments on commit a873011

Please sign in to comment.