Sidekiq

Sidekiq runs background jobs for Ruby applications. It runs on KiviDB without changes to your code: point REDISURL at a KiviDB database that has the Lua…

Sidekiq runs background jobs for Ruby applications. It runs on KiviDB without changes to your code: point REDIS_URL at a KiviDB database that has the Lua build.

Requirements

KiviDB1.1.0 or later
BuildLua (see Integrations)
SidekiqTested with 8.1 on Ruby 3.4

The Lua build is not optional. On the default build Sidekiq starts and runs plain jobs, but scheduled jobs (perform_in, perform_at) and retries are never picked up, and no error is raised.

Create the database

On KiviDB Cloud, turn on Job queues (BullMQ, Sidekiq) when you create the database. For an existing database, turn on Lua scripting under Configuration.

Self-hosted:

docker run -p 6379:6380 kividb/kividb:v1.2.2-lua

Connect

Use the endpoint, port and credentials from the database's overview. The username goes in the URL.

# config/initializers/sidekiq.rb
url = "redis://kividbapp:#{ENV.fetch('KIVIDB_PASSWORD')}@your-name.cloud.kividb.io:6379/0"

Sidekiq.configure_server { |config| config.redis = { url: url } }
Sidekiq.configure_client { |config| config.redis = { url: url } }

A job is written as usual:

class WelcomeEmailJob
  include Sidekiq::Job
  sidekiq_options retry: 5

  def perform(user_id)
    UserMailer.welcome(user_id).deliver_now
  end
end

WelcomeEmailJob.perform_async(42)
WelcomeEmailJob.perform_in(10 * 60, 42)

With TLS turned on for the database, use rediss:// and the TLS port, and give the CA certificate from Configuration:

url = "rediss://kividbapp:#{ENV.fetch('KIVIDB_PASSWORD')}@your-name.cloud.kividb.io:6380/0"
tls = { ca_file: "kividb-ca.pem" }

Sidekiq.configure_server { |config| config.redis = { url: url, ssl_params: tls } }
Sidekiq.configure_client { |config| config.redis = { url: url, ssl_params: tls } }

What is tested

Our suite runs these against KiviDB and against Redis 8, and expects the same result from both:

  • A Sidekiq process registering itself, and deregistering on a clean stop
  • Jobs pushed in bulk and run exactly once
  • Scheduled jobs, run after their delay and not before
  • Retries from the retry set
  • Jobs with no retries left moving to the dead set
  • Several queues with weights
  • Processed and failed counters
  • The Sidekiq API: queues, the scheduled, retry and dead sets, and clearing them
  • No Redis errors in the Sidekiq log

Sidekiq Pro and Sidekiq Enterprise are not part of the suite.

Troubleshooting

Scheduled jobs and retries never run. The database is on the default build. Turn on Lua scripting.

NOPERM User default has no permissions to run the 'hello' command. The database was created before this was allowed. Change a database password under Access Credentials once, which rewrites the database's users, and connect again.