From e7f1ecb35d0522890a31b9ba44ebf10b05da80a8 Mon Sep 17 00:00:00 2001 From: Christoph Helma Date: Thu, 15 Mar 2012 12:24:47 +0100 Subject: dynamic adjustment of task poll times --- lib/task.rb | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) (limited to 'lib/task.rb') diff --git a/lib/task.rb b/lib/task.rb index 9921c4c..2f79cf1 100644 --- a/lib/task.rb +++ b/lib/task.rb @@ -65,10 +65,14 @@ module OpenTox # waits for a task, unless time exceeds or state is no longer running # @param [optional,Numeric] dur seconds pausing before checking again for completion - def wait(dur=0.3) - due_to_time = Time.new + DEFAULT_TASK_MAX_DURATION - while running? + # TODO: add waiting task + def wait + start_time = Time.new + due_to_time = start_time + DEFAULT_TASK_MAX_DURATION + dur = 0 + while running? sleep dur + dur = [[(Time.new - start_time)/20.0,0.3].max,300.0].min time_out_error "max wait time exceeded ("+DEFAULT_TASK_MAX_DURATION.to_s+"sec), task: '"+@uri.to_s+"'" if (Time.new > due_to_time) end end @@ -88,8 +92,6 @@ module OpenTox RestClientWrapper.head(@uri).code == 200 end - # TODO: add queued? - def error? code = RestClientWrapper.head(@uri).code code >= 400 and code != 503 -- cgit v1.2.3