[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

fish man

4/3/2006 8:47:00 AM

Hi quick question, I have a soap server and soap client ruby scripts.

When I try to run the soap client without starting up the up the server
the client program crashes out, as you would expect. But I'd like to
catch that exception and wait 5 min's before it tries again.

so I have a little bit of code that goes.
begin
Timeout::timeout(900) do #try 3 times before quiting.
not_connected = true
while not_connected == true do
begin
@soap_wrp =
SOAP::RPC::Driver.new("http://localhost:9001", "http://fasw111/Submit")
not_connected = false
puts @soap_wrp
rescue SystemExit
not_connected = true
sleep 300 #sleep for 5 min
end
end
#do some soap stuff

rescue Timeout::Error
puts "time out error"
soap_wrp = -1
end


But once the SOAP::RPC::Driver.new fails to find the server there seems
to be a complete crashs out of the code.
Does anyone know how I can get around this?

Thanks.
fishman2001.

--
Posted via http://www.ruby-....


5 Answers

Erik Hollensbe

4/4/2006 2:12:00 PM

0

On 2006-04-03 01:47:03 -0700, fish man <danperrett07087@yahoo.com> said:

> Hi quick question, I have a soap server and soap client ruby scripts.
>
> When I try to run the soap client without starting up the up the server
> the client program crashes out, as you would expect. But I'd like to
> catch that exception and wait 5 min's before it tries again.
>
>

A couple of thoughts that are non-specific to the SOAP modules:

Try rescuing on Exception instead of SystemExit... If that fixed your
troubles, then you know you're catching the wrong exception. Another
important thing to do (obviously) is read the information on whatever
is terminating execution.

Aside, your timeout is not going to ensure trying 3 times. It will wait
900 seconds, but depending on how long the connection takes to timeout,
your 300 second sleep will cause more troubles.

What might be better is something like this:

3.times do
begin
@soap_wrp = SOAP::Stuff # fill in your driver here
rescue Exception => e
puts e # for debugging
end
end

exit(-1) unless @soap_wrp # @soap_wrp is nil, we are not connected

# rest of code..

This may look just like a shorter solution, but it solves a lot of
potential problems due to eliminating unnecessary complexity.

Erik Hollensbe

4/4/2006 2:24:00 PM

0

On 2006-04-04 07:12:04 -0700, Erik Hollensbe <erik@hollensbe.org> said:
> 3.times do
> begin
> @soap_wrp = SOAP::Stuff # fill in your driver here
> rescue Exception => e
> puts e # for debugging
> end

There should be a 'break if @soap_wrp' right here.

> end
>
> exit(-1) unless @soap_wrp # @soap_wrp is nil, we are not connected
>
> # rest of code..


fish man

4/4/2006 4:05:00 PM

0

Erik Hollensbe wrote:
> On 2006-04-04 07:12:04 -0700, Erik Hollensbe <erik@hollensbe.org> said:
>> 3.times do
>> begin
>> @soap_wrp = SOAP::Stuff # fill in your driver here
>> rescue Exception => e
>> puts e # for debugging
>> end
>
> There should be a 'break if @soap_wrp' right here.

I did this, tried to catch the exception, but it still crashes out.
give the error
Errno::ECONNREFUSED

any ideas?

--
Posted via http://www.ruby-....


Robert Klemme

4/10/2006 10:20:00 AM

0

fish man wrote:
> Erik Hollensbe wrote:
>> On 2006-04-04 07:12:04 -0700, Erik Hollensbe <erik@hollensbe.org> said:
>>> 3.times do
>>> begin
>>> @soap_wrp = SOAP::Stuff # fill in your driver here
>>> rescue Exception => e
>>> puts e # for debugging
>>> end
>> There should be a 'break if @soap_wrp' right here.
>
> I did this, tried to catch the exception, but it still crashes out.
> give the error
> Errno::ECONNREFUSED
>
> any ideas?
>

I'd go down a completely different route:

def doit()
@attempts = 0
begin
# open connection and then use it
# ...
rescue YourConnectionExceptionHere
@attempts += 1
raise if @attempts >= 3
sleep 300
retry
end
end

Kind regards

robert

Jason Guiditta

5/14/2007 7:29:00 PM

0

I know this is a VERY stale thread, but would this Exception actually
catch a Timeout? I ask because I need to do this so our app doesn't get
hung up if the webservice we are calling tips over. Perhaps (likely)
there is something obvious I have just not seen, but it seems like this
should be fairly trivial to do.

-jay


--
Posted via http://www.ruby-....