summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristoph Helma <helma@in-silico.ch>2012-07-13 12:24:37 +0200
committerChristoph Helma <helma@in-silico.ch>2012-07-13 12:24:37 +0200
commit66dae77b92308bb09781948ad4caf90b770d1ef8 (patch)
tree029f0f32cfd4a94922a58229fde3a531f1705ecf
parentbf6834445feb6f93f0a20359462dbd1e7e89f4b8 (diff)
wait for tasks in post/put requests
-rw-r--r--lib/dataset.rb6
-rw-r--r--lib/opentox.rb8
-rw-r--r--lib/task.rb6
3 files changed, 11 insertions, 9 deletions
diff --git a/lib/dataset.rb b/lib/dataset.rb
index ed0ccdd..a6c22d0 100644
--- a/lib/dataset.rb
+++ b/lib/dataset.rb
@@ -13,9 +13,9 @@ module OpenTox
append RDF.type, RDF::OT.OrderedDataset
end
- def upload filename
- file = File.new filename
- RestClientWrapper.put(@uri, {:file => file}, {:subjectid => @subjectid})
+ def upload filename, wait=true
+ uri = RestClientWrapper.put(@uri, {:file => File.new(filename)}, {:subjectid => @subjectid})
+ OpenTox::Task.new(uri).wait if URI.task?(uri) and wait
end
def get
diff --git a/lib/opentox.rb b/lib/opentox.rb
index 9225bb0..019699b 100644
--- a/lib/opentox.rb
+++ b/lib/opentox.rb
@@ -67,20 +67,22 @@ module OpenTox
end
# Post object to webservice
- def post service_uri
- RestClientWrapper.post service_uri, to_ntriples, { :content_type => "text/plain", :subjectid => @subjectid}
+ def post service_uri, wait=true
+ uri = RestClientWrapper.post service_uri, to_ntriples, { :content_type => "text/plain", :subjectid => @subjectid}
+ OpenTox::Task.new(uri).wait if URI.task?(uri) and wait
#rescue # fall back to rdfxml
#RestClientWrapper.post service_uri, to_rdfxml, { :content_type => "application/rdf+xml", :subjectid => @subjectid}
end
# Save object at webservice
- def put
+ def put wait=true
append RDF::DC.modified, DateTime.now
#begin
RestClientWrapper.put @uri.to_s, self.to_ntriples, { :content_type => "text/plain", :subjectid => @subjectid}
#rescue # fall back to rdfxml
#RestClientWrapper.put @uri.to_s, self.to_rdfxml, { :content_type => "application/rdf+xml", :subjectid => @subjectid}
#end
+ OpenTox::Task.new(uri).wait if URI.task?(uri) and wait
end
# Delete object at webservice
diff --git a/lib/task.rb b/lib/task.rb
index f3f7f6b..4f446b7 100644
--- a/lib/task.rb
+++ b/lib/task.rb
@@ -12,7 +12,7 @@ module OpenTox
task = Task.new uri, subjectid
task[RDF::OT.hasStatus] = "Running"
params.each { |k,v| task[k] = v }
- task.put
+ task.put false
pid = fork do
begin
result_uri = yield
@@ -61,13 +61,13 @@ module OpenTox
def cancel
kill
self.[]=(RDF::OT.hasStatus, "Cancelled")
- put
+ put false
end
def completed(uri)
self.[]=(RDF::OT.resultURI, uri)
self.[]=(RDF::OT.hasStatus, "Completed")
- put
+ put false
end
# waits for a task, unless time exceeds or state is no longer running