summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristoph Helma <helma@in-silico.ch>2012-05-07 14:31:08 +0000
committerChristoph Helma <helma@in-silico.ch>2012-05-07 14:31:08 +0000
commit6f66d558e8512f7f2b0071c2d9c87ea69ec55472 (patch)
tree36789a92b9ea26a419c9e1573b0111bf40830d61
parentabec0b78a8f8ce71fa27a30210b1383ce998b655 (diff)
error code from error report
-rw-r--r--application.rb22
1 files changed, 6 insertions, 16 deletions
diff --git a/application.rb b/application.rb
index a27b48a..e0a33ab 100644
--- a/application.rb
+++ b/application.rb
@@ -3,13 +3,8 @@ module OpenTox
helpers do
def status_code uri
- sparql = "SELECT ?o WHERE {<#{uri}> <#{RDF::OT.hasStatus}> ?o. }"
- result = Backend::FourStore.query(sparql,nil)
- unless result.size == 1
- # TODO: identify error cause and fix, simultanous 4stoer access?
- internal_server_error "Cannot find status for '#{uri}', candidates are #{result.inspect}"
- end
- status = result.last.gsub(/"|'/,'').gsub(/\^\^.*$/,'')
+ sparql = "SELECT ?o WHERE { GRAPH <#{uri}> { <#{uri}> <#{RDF::OT.hasStatus}> ?o. } }"
+ status = Backend::FourStore.query(sparql,nil).last.gsub(/"|'/,'').gsub(/\^\^.*$/,'')
case status
when "Completed"
200
@@ -18,10 +13,12 @@ module OpenTox
when "Cancelled"
503
when "Error"
- # TODO: get code from error report
- 500
+ sparql = "SELECT ?code WHERE { GRAPH <#{uri}> { <#{uri}> <#{RDF::OT.error}> ?error. ?error <#{RDF::OT.statusCode}> ?code } }"
+ code = Backend::FourStore.query(sparql,nil).last.to_i
+ code ? code : 500
end
end
+
end
get '/task/:id/?' do
@@ -30,12 +27,6 @@ module OpenTox
halt status_code(uri), rdf
end
-=begin
- get '/:id/:status/?' do
- end
-
-=end
-
put '/task/:id/:status/?' do
uri = uri("/task/#{params[:id]}")
sparql = []
@@ -55,7 +46,6 @@ module OpenTox
sparql << "INSERT DATA { GRAPH <#{uri}> {<#{uri}> <#{RDF::OT.hasStatus}> \"Cancelled\"}}"
sparql << "INSERT DATA { GRAPH <#{uri}> {<#{uri}> <#{RDF::OT.finished_at}> \"#{DateTime.now}\"}}"
when "Error"
- puts "ERROR"
sparql << "DELETE DATA { GRAPH <#{uri}> {<#{uri}> <#{RDF::OT.hasStatus}> \"Running\"}}"
sparql << "INSERT DATA { GRAPH <#{uri}> {<#{uri}> <#{RDF::OT.hasStatus}> \"Error\"}}"
sparql << "INSERT DATA { GRAPH <#{uri}> {<#{uri}> <#{RDF::OT.finished_at}> \"#{DateTime.now}\"}}"