stefanobaldo
stefanobaldo

Reputation: 2063

Sidekiq Timeout

I'm using sidekiq in my Rails App to asynchronously execute a stored procedure in my SQL Server database when the user moves from one specific page to another.

The problem is that the stored procedure takes up to 4 minutes to complete and sidekiq returns a timeout message (and then retry).

I don't want to change my application's global database timeout setting in database.yml (I don't even know if it would resolve, but I can't do that).

Is there any way to tell sidekiq that my method can take long and then stop getting timeout errors?

I really appreciate any help.

UPDATE #1

2013-06-03T17:14:18Z 6136 TID-1ac4ik GeneratePropertyProfile JID-de571df94f21b9159c74db6b INFO: start

2013-06-03T17:19:03Z 6136 TID-1ac4ik GeneratePropertyProfile JID-de571df94f21b9159c74db6b INFO: fail: 285.218 sec

2013-06-03T17:19:03Z 6136 TID-1ac4ik WARN: {"retry"=>true, "queue"=>"default", "class"=>"GeneratePropertyProfile", "args"=>[{"id"=>41915658}], "jid"=>"de571df94f21b9159c74db6b", "error_message"=>"TinyTds::Error: Adaptive Server connection timed out: EXEC gaiainc.sp_wait", "error_class"=>"ActiveRecord::StatementInvalid", "failed_at"=>2013-06-03 17:19:03 UTC, "retry_count"=>0}

2013-06-03T17:19:03Z 6136 TID-1ac4ik WARN: TinyTds::Error: Adaptive Server connection timed out: EXEC gaiainc.sp_wait

UPDATE #2

I got it to work without changing my database.yml. However, I had to add the following code in my initializers/sidekiq.rb:

Sidekiq.configure_server do |config|
  ActiveRecord::Base.connection.disconnect!
  ActiveRecord::Base.configurations[Rails.env]['timeout'] = 300000
  ActiveRecord::Base.establish_connection
end

I know it's an ugly solution but I had no time to find another solution to make it work. If anyone has a cleaner solution, please reply to this topic.

Thank you!

Upvotes: 2

Views: 12734

Answers (1)

Ivan Shamatov
Ivan Shamatov

Reputation: 1416

TERM signals that Sidekiq should shut down within the -t timeout option. Any workers that do not finish within the timeout are forcefully terminated and their messages are lost. The timeout defaults to 25 seconds

The Sidekiq TERM timeout is set in config/sidekiq.yml or with the -t parameter. Sidekiq will do its best to exit by this timeout when it receives TERM.

:timeout: 300

Upvotes: 7

Related Questions