diff options
author | Christoph Helma <helma@in-silico.ch> | 2012-02-16 22:17:50 +0000 |
---|---|---|
committer | Christoph Helma <helma@in-silico.ch> | 2012-02-16 22:17:50 +0000 |
commit | 0600fdc62e7446caa75ffcff4d097338818e0df9 (patch) | |
tree | 0f0ccdc884e333004eddb6e4b1074b721ecaa552 /lib | |
parent | 6cacf7bbc3545ed87e21d0ca5a19ab4300699fdc (diff) |
Task.wait_for_completion fixed
Diffstat (limited to 'lib')
-rw-r--r-- | lib/opentox-client.rb | 2 | ||||
-rw-r--r-- | lib/task.rb | 11 |
2 files changed, 11 insertions, 2 deletions
diff --git a/lib/opentox-client.rb b/lib/opentox-client.rb index 7c7fb11..0bd048c 100644 --- a/lib/opentox-client.rb +++ b/lib/opentox-client.rb @@ -1,4 +1,6 @@ +require "opentox-client/version" require 'rubygems' +require "bundler/setup" require 'rdf' require 'rdf/raptor' require "rest-client" diff --git a/lib/task.rb b/lib/task.rb index aee6c62..50616d7 100644 --- a/lib/task.rb +++ b/lib/task.rb @@ -7,7 +7,13 @@ module OpenTox def self.create service_uri, params={} task = Task.new RestClient.post(service_uri,params).chomp - pid = Spork.spork { yield } + pid = Spork.spork do + begin + task.completed yield + rescue => error + task.error error + end + end task.pid = pid task end @@ -33,6 +39,7 @@ module OpenTox def wait_for_completion(dur=0.3) due_to_time = Time.new + DEFAULT_TASK_MAX_DURATION while self.running? + sleep dur raise "max wait time exceeded ("+DEFAULT_TASK_MAX_DURATION.to_s+"sec), task: '"+@uri.to_s+"'" if (Time.new > due_to_time) end end @@ -46,7 +53,7 @@ module OpenTox res = RestClient.put(File.join(@uri,method.sub(/=/,'')),{}) super unless res.code == 200 when /\?/ - return metadata[RDF::OT.hasStatus] == method.sub(/\?/,'').capitalize + return hasStatus == method.sub(/\?/,'').capitalize else return metadata[RDF::OT[method]].to_s end |