chicks / sugarcrm

A ruby based REST Client for SugarCRM
MIT License
90 stars 64 forks source link

Timeout setting, is it possible ? #59

Closed alexdesi closed 13 years ago

alexdesi commented 13 years ago

Is it possible to set the timeout for the Sugar call ? if I run : c = SugarCRM::Contact.find_by_last_name 'Rossi' or any other call, and my connection is down, I will get a timeout error after a very long time !

How can I set this time ?

(anyway, I am running sugar calls in background :) )

thank you

Alexdesi

chicks commented 13 years ago

Sure... something like:

SugarCRM.connection.connection.read_timeout = 100

Because you need to set the read timeout on the net/http class that the connection is built on.

davidsulc commented 13 years ago

Hmmm. It may not be that simple: in connect.rb, line 79 we rescue Timeout::Error and retry 3 times (to placate connection issues) before giving up...

chicks commented 13 years ago

This is an excellent point. The only situation where adjusting read_timeout helps is when your CRM is REALLY slow and it never responds faster than the timeout. Specifically, when subsequent retries do not result in a quicker response.

davidsulc commented 13 years ago

Alex, if your connection is down before you run the script (i.e. you never logged in), the gem should raise a SugarCRM::NoActiveSession exception. If the connection drops after you have already logged in, it should restore the connection for you automatically (i.e. without your needing to do anything).

alexdesi commented 13 years ago

I experimented the connection drop after the login, that is a very critical if you are using sugar blocking calls. I've seen that Timeout::Error is about 3 minutes with the defaults settings (I think it's too long time). I have to try to modify SugarCRM.connection.connection.read_timeout (as chicks suggest), anyway, now I am running the sugar calls in background, so the issue is less important for me, but a simple way to set the timeout would be good.

Thank you

chicks commented 13 years ago

Wouldn't be hard to make it an option to SugarCRM.connect that just sets the net/http read_timeout.

davidsulc commented 13 years ago

Soooooooo. It turns out I had already added the timeout attribute in the connection pool, but read-only. I patched it to make it writable. I'm leaving the default timeout at 10s for now, to accomodate large result sets, but it could probably be reduced...

You can now set the timeout with SugarCRM.session.connection_pool.timeout = 5.

To upgrade your gem:

The reason there's a "try 3 times" policy is that I've observed that when I had timeout errors, I would get 3 consecutive errors, and then the connection would go through. Very strange, and I don't know if it accepts other setups. In any case, a 3 minute timeout is suspicious, since it's way over the "4 times the 10s timeout"...

Let us know if this doesn't address your problems (and close the issue if it does ;-D).

chicks commented 13 years ago

New gem has been released. Let me know if you need anything else!

vivek2007 commented 8 years ago

/home/vivek/.rvm/gems/ruby-1.9.3-p551@sugarcrmtwo/gems/sugarcrm-0.9.18/lib/sugarcrm/session.rb:212:in parse_connection_pool_options': You have a nil object when you didn't expect it! (NoMethodError) You might have expected an instance of Array. The error occurred while evaluating nil.delete from /home/vivek/.rvm/gems/ruby-1.9.3-p551@sugarcrmtwo/gems/sugarcrm-0.9.18/lib/sugarcrm/session.rb:30:infrom_hash' from /home/vivek/Documents/newcrm/sugar_on_rails_basic/config/initializers/sugarcrm.rb:6:in <top (required)>' from /home/vivek/.rvm/gems/ruby-1.9.3-p551@sugarcrmtwo/gems/activesupport-3.0.0/lib/active_support/dependencies.rb:235:inload' from /home/vivek/.rvm/gems/ruby-1.9.3-p551@sugarcrmtwo/gems/activesupport-3.0.0/lib/active_support/dependencies.rb:235:in block in load' from /home/vivek/.rvm/gems/ruby-1.9.3-p551@sugarcrmtwo/gems/activesupport-3.0.0/lib/active_support/dependencies.rb:225:inblock in load_dependency' from /home/vivek/.rvm/gems/ruby-1.9.3-p551@sugarcrmtwo/gems/activesupport-3.0.0/lib/active_support/dependencies.rb:591:in new_constants_in' from /home/vivek/.rvm/gems/ruby-1.9.3-p551@sugarcrmtwo/gems/activesupport-3.0.0/lib/active_support/dependencies.rb:225:inload_dependency' from /home/vivek/.rvm/gems/ruby-1.9.3-p551@sugarcrmtwo/gems/activesupport-3.0.0/lib/active_support/dependencies.rb:235:in load' from /home/vivek/.rvm/gems/ruby-1.9.3-p551@sugarcrmtwo/gems/railties-3.0.0/lib/rails/engine.rb:201:inblock (2 levels) in class:Engine' from /home/vivek/.rvm/gems/ruby-1.9.3-p551@sugarcrmtwo/gems/railties-3.0.0/lib/rails/engine.rb:200:in each' from /home/vivek/.rvm/gems/ruby-1.9.3-p551@sugarcrmtwo/gems/railties-3.0.0/lib/rails/engine.rb:200:inblock in class:Engine' from /home/vivek/.rvm/gems/ruby-1.9.3-p551@sugarcrmtwo/gems/railties-3.0.0/lib/rails/initializable.rb:25:in instance_exec' from /home/vivek/.rvm/gems/ruby-1.9.3-p551@sugarcrmtwo/gems/railties-3.0.0/lib/rails/initializable.rb:25:inrun' from /home/vivek/.rvm/gems/ruby-1.9.3-p551@sugarcrmtwo/gems/railties-3.0.0/lib/rails/initializable.rb:50:in block in run_initializers' from /home/vivek/.rvm/gems/ruby-1.9.3-p551@sugarcrmtwo/gems/railties-3.0.0/lib/rails/initializable.rb:49:ineach' from /home/vivek/.rvm/gems/ruby-1.9.3-p551@sugarcrmtwo/gems/railties-3.0.0/lib/rails/initializable.rb:49:in run_initializers' from /home/vivek/.rvm/gems/ruby-1.9.3-p551@sugarcrmtwo/gems/railties-3.0.0/lib/rails/application.rb:134:ininitialize!' from /home/vivek/.rvm/gems/ruby-1.9.3-p551@sugarcrmtwo/gems/railties-3.0.0/lib/rails/application.rb:77:in method_missing' from /home/vivek/Documents/newcrm/sugar_on_rails_basic/config/environment.rb:5:in<top (required)>' from /home/vivek/Documents/newcrm/sugar_on_rails_basic/config.ru:3:in require' from /home/vivek/Documents/newcrm/sugar_on_rails_basic/config.ru:3:inblock in

' from /home/vivek/.rvm/gems/ruby-1.9.3-p551@sugarcrmtwo/gems/rack-1.2.8/lib/rack/builder.rb:46:in instance_eval' from /home/vivek/.rvm/gems/ruby-1.9.3-p551@sugarcrmtwo/gems/rack-1.2.8/lib/rack/builder.rb:46:ininitialize' from /home/vivek/Documents/newcrm/sugar_on_rails_basic/config.ru:1:in new' from /home/vivek/Documents/newcrm/sugar_on_rails_basic/config.ru:1:in
' from /home/vivek/.rvm/gems/ruby-1.9.3-p551@sugarcrmtwo/gems/rack-1.2.8/lib/rack/builder.rb:35:in eval' from /home/vivek/.rvm/gems/ruby-1.9.3-p551@sugarcrmtwo/gems/rack-1.2.8/lib/rack/builder.rb:35:inparse_file' from /home/vivek/.rvm/gems/ruby-1.9.3-p551@sugarcrmtwo/gems/rack-1.2.8/lib/rack/server.rb:162:in app' from /home/vivek/.rvm/gems/ruby-1.9.3-p551@sugarcrmtwo/gems/rack-1.2.8/lib/rack/server.rb:253:inwrapped_app' from /home/vivek/.rvm/gems/ruby-1.9.3-p551@sugarcrmtwo/gems/rack-1.2.8/lib/rack/server.rb:204:in start' from /home/vivek/.rvm/gems/ruby-1.9.3-p551@sugarcrmtwo/gems/railties-3.0.0/lib/rails/commands/server.rb:65:instart' from /home/vivek/.rvm/gems/ruby-1.9.3-p551@sugarcrmtwo/gems/railties-3.0.0/lib/rails/commands.rb:30:in block in <top (required)>' from /home/vivek/.rvm/gems/ruby-1.9.3-p551@sugarcrmtwo/gems/railties-3.0.0/lib/rails/commands.rb:27:intap' from /home/vivek/.rvm/gems/ruby-1.9.3-p551@sugarcrmtwo/gems/railties-3.0.0/lib/rails/commands.rb:27:in <top (required)>' from script/rails:6:inrequire' from script/rails:6:in `