From 66dae77b92308bb09781948ad4caf90b770d1ef8 Mon Sep 17 00:00:00 2001 From: Christoph Helma Date: Fri, 13 Jul 2012 12:24:37 +0200 Subject: wait for tasks in post/put requests --- lib/dataset.rb | 6 +++--- lib/opentox.rb | 8 +++++--- lib/task.rb | 6 +++--- 3 files changed, 11 insertions(+), 9 deletions(-) (limited to 'lib') 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 -- cgit v1.2.3