From 0600fdc62e7446caa75ffcff4d097338818e0df9 Mon Sep 17 00:00:00 2001 From: Christoph Helma Date: Thu, 16 Feb 2012 22:17:50 +0000 Subject: Task.wait_for_completion fixed --- lib/opentox-client.rb | 2 ++ lib/task.rb | 11 +++++++++-- 2 files changed, 11 insertions(+), 2 deletions(-) (limited to 'lib') 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 -- cgit v1.2.3