summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorChristoph Helma <helma@in-silico.ch>2012-03-15 12:24:47 +0100
committerChristoph Helma <helma@in-silico.ch>2012-03-15 12:24:47 +0100
commite7f1ecb35d0522890a31b9ba44ebf10b05da80a8 (patch)
treeabd520d76c78b9d38a387f83ccbbf5a4d484c46b /lib
parent1652bc3f3e635948fc3a73817f407adc6dee071a (diff)
dynamic adjustment of task poll times
Diffstat (limited to 'lib')
-rw-r--r--lib/task.rb12
1 files changed, 7 insertions, 5 deletions
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