Search code examples
ruby-on-railsredissidekiq

How the Sidekiq server process pulls jobs from the queue in Redis?


I've two Rails application running on two different instance(lets say Server1 and Server2) but they have similar codes and shares the same Postgresql DB.

I installed Sidekiq and pushing the jobs in Queue from both the servers, but I'm running the Sidekiq process only in Server1.

I've single Redis server and its running on Server1 which shares the Redis with Server2.

If a job pushed from Server2 it getting processed in Server1's Sidekiq process and its what I actually wanted.

My question is

  • How the Sidekiq process on Server1 knows that a job is pushed in Redis?

  • Whether the Sidekiq process continuously checks on the Redis server for any new jobs or the Redis server is intimating to the Sidekiq process about the new job?

I got confused and amazed about this!!!

Could anyone please clarify the Sidekiq's process to get the job from Redis server?

It will be helpful for newbies like me.


Solution

  • Sidekiq uses redis command named BRPOP.

    This command gets an element from a list (which is your job queue). And if the list is empty, it waits for element to appear and then pops/returns it. This also works with multiple queues at the same time.

    So no, sidekiq does not poll redis and redis does not push notifications to sidekiq.