summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristoph Helma <helma@in-silico.ch>2010-11-24 11:48:32 +0100
committerChristoph Helma <helma@in-silico.ch>2010-11-24 11:48:32 +0100
commit6e5aa1678e7d0380de77e462347ae2260fd3051b (patch)
tree9b4f20628e52157a9a0a95659a8e52044e8b08c0
parent40d607c935e27ab26a2f2dd1d641717c9d6a5e31 (diff)
status 503 for rejected tasks
-rw-r--r--lazar.rb15
1 files changed, 12 insertions, 3 deletions
diff --git a/lazar.rb b/lazar.rb
index 0a9dddf..e543802 100644
--- a/lazar.rb
+++ b/lazar.rb
@@ -1,5 +1,13 @@
require "haml"
-#require "lazar-helper"
+
+helpers do
+ def uri_available?(urlStr)
+ url = URI.parse(urlStr)
+ Net::HTTP.start(urlStr.host, urlStr.port) do |http|
+ return http.head(urlStr.request_uri).code == "200"
+ end
+ end
+end
# Get model representation
# @return [application/rdf+xml,application/x-yaml] Model representation
@@ -59,8 +67,8 @@ post '/:id/?' do
response['Content-Type'] = 'text/uri-list'
if compound_uri
- #cache = PredictionCache.first(:model_uri => @lazar.uri, :compound_uri => compound_uri)
- #return cache.dataset_uri if cache
+ cache = PredictionCache.first(:model_uri => @lazar.uri, :compound_uri => compound_uri)
+ return cache.dataset_uri if cache and uri_available?(cache.dataset_uri)
begin
prediction_uri = @lazar.predict(compound_uri,true).uri
PredictionCache.create(:model_uri => @lazar.uri, :compound_uri => compound_uri, :dataset_uri => prediction_uri)
@@ -74,6 +82,7 @@ post '/:id/?' do
task = OpenTox::Task.create("Predict dataset",url_for("/#{@lazar.id}", :full)) do
@lazar.predict_dataset(dataset_uri).uri
end
+ halt 503,task.uri+"\n" if task.status == "Cancelled"
halt 202,task.uri
end