I'm trying to use sidekiq to process some requests in background (it's integrated with padrino framework).
My expectation was that once the worker got called, the request handler would return immediately the answer to user.
In order to be sure it was working properly I implemented a worker that would print some messages and sleep for some 44s prior to finish it's processing (to simulate a long processing in background).
For my surprise, the request got stuck until the worker had the job finished. Only after that the request handler could return an answer to user.
At first I thought that the sleep function could be the problem, so I replaced the sleep function by a busy while but I have the same behavior: the request handler got hanged until the worker finished its task.
Any idea why is this happening?
You can see the following :
request handler:
get :hardworker, map: '/hardworker' do
logger.info "I'll call HardWorker"
HardWorker.perform_async(44)
logger.info "HardWorker was called"
return "The job should still be running in background."
end
Sidekiq worker:
class HardWorker
include Sidekiq::Worker
def perform(count)
logger.info "Doing hard work"
Sidekiq.redis { |c| logger.info "redis location: [#{c.client.location }]" }
redis_info = Sidekiq.redis { |conn| conn.info }
logger.info "connected clients: [#{redis_info['connected_clients']}]"
sleep count
logger.info "hard work was done"
end
end
The redis server is running:
ps -ef | grep redis
returns
redis 1232 1 0 16:54 ? 00:00:09 /usr/bin/redis-server 127.0.0.1:6379
as well as sidekiq server:
bundle exec sidekiq -r ./config/boot.rb -v
2015-06-06T20:31:26.207Z 3343 TID-8614g INFO: Booting Sidekiq 3.3.4 with redis options {:url=>"redis://127.0.0.1:6379/0", :concurrency=>25}
Also, from logs I put in the worker we can see that client apparently is connected to redis:
INFO - redis location: [127.0.0.1:6379]
INFO - connected clients: [3]
sidekiq version: 3.3.4 redis server: 2.8.4 ruby: 2.1.2p95
Note: I mounted sidekiq web tool on my padrino and it shows 0 for all stats (Processed, Failed, Busy, Enqueued, Retries, Scheduled, Dead) both prior and after the worker has executed.
The sample project can be downloaded from here: https://github.com/plicatibu/sidekiq-problem.git