@@ -97,14 +97,18 @@ def send_request(params, opts = {})
9797 # The contents of the 'jobresult' element are returned upon completion of the command.
9898
9999 def send_async_request ( params , opts = { } )
100+ request_timeout = opts [ :async_timeout ] || @async_timeout
101+ poll_interval = opts [ :async_poll_interval ] || @async_poll_interval
102+ validate_async_timeouts! ( request_timeout , poll_interval )
103+
100104 data = send_request ( params , opts )
101105
102106 params = {
103107 'command' => 'queryAsyncJobResult' ,
104108 'jobid' => data [ k ( 'jobid' ) ]
105109 }
106110
107- max_tries . times do
111+ max_tries ( request_timeout , poll_interval ) . times do
108112 data = send_request ( params )
109113 print "." if @verbose
110114
@@ -116,7 +120,7 @@ def send_async_request(params, opts = {})
116120 end
117121
118122 STDOUT . flush if @verbose
119- sleep @async_poll_interval
123+ sleep poll_interval
120124 end
121125
122126 raise TimeoutError , "Asynchronous request timed out."
@@ -128,11 +132,15 @@ def validate_input!
128132 raise InputError , "API URL not set." if @api_url == nil
129133 raise InputError , "API KEY not set." if @api_key == nil
130134 raise InputError , "API SECRET KEY not set." if @secret_key == nil
131- raise InputError , "ASYNC POLL INTERVAL must be at least 1." if @async_poll_interval < 1.0
132- raise InputError , "ASYNC TIMEOUT must be at least 60." if @async_timeout < 60
135+ validate_async_timeouts! ( @async_timeout , @async_poll_interval )
133136 raise InputError , "REQUEST RETRIES must be at least 1." if @request_retries < 1
134137 end
135138
139+ def validate_async_timeouts! ( timeout , interval )
140+ raise InputError , "ASYNC POLL INTERVAL must be at least 1." if interval < 1.0
141+ raise InputError , "ASYNC TIMEOUT must be at least 60." if timeout < 60
142+ end
143+
136144 def params_to_data ( params )
137145 params_arr = params . sort . map do |key , value |
138146 case value
@@ -160,8 +168,8 @@ def create_signature(data)
160168 CGI . escape ( signature )
161169 end
162170
163- def max_tries
164- ( @async_timeout / @async_poll_interval ) . round
171+ def max_tries ( timeout , interval )
172+ ( timeout / interval ) . round
165173 end
166174
167175 def escape ( input )
0 commit comments