Introduction
Sidekiq adapter setup lets your Rails app run background jobs fast and efficiently using Sidekiq.
Sidekiq adapter setup lets your Rails app run background jobs fast and efficiently using Sidekiq.
# config/application.rb or config/environments/production.rb
Rails.application.configure do
config.active_job.queue_adapter = :sidekiq
end# In config/application.rb module YourApp class Application < Rails::Application config.load_defaults 7.0 config.active_job.queue_adapter = :sidekiq end end
# In config/environments/production.rb
Rails.application.configure do
config.active_job.queue_adapter = :sidekiq
endThis example shows how to set Sidekiq as the adapter, define a simple job, and enqueue it.
# Gemfile gem 'sidekiq' # Run bundle install # config/application.rb module MyApp class Application < Rails::Application config.load_defaults 7.0 config.active_job.queue_adapter = :sidekiq end end # app/jobs/hard_worker_job.rb class HardWorkerJob < ApplicationJob queue_as :default def perform(name) puts "Doing hard work for #{name}" end end # To enqueue the job in Rails console HardWorkerJob.perform_later('Alice')
Sidekiq requires Redis to be installed and running on your machine or server.
Use bundle exec sidekiq to start the Sidekiq worker process.
Check Sidekiq web UI for monitoring jobs by mounting it in your routes.
Set config.active_job.queue_adapter = :sidekiq to use Sidekiq in Rails.
Sidekiq runs jobs in the background using Redis queues.
Make sure Redis and Sidekiq worker are running to process jobs.
config.active_job.queue_adapter to set the background job processor.:sidekiq to config.active_job.queue_adapter.config/application.rb?:sidekiq is the correct way to specify the adapter.config.active_job.queue_adapter = :sidekiq
class MyJob < ApplicationJob
def perform
puts 'Job is running'
end
end
MyJob.perform_laterperform_later enqueues the job to Sidekiq to run asynchronously, not immediately.puts runs when Sidekiq worker processes the job, so output appears asynchronously in Sidekiq logs or console.config.active_job.queue_adapter = :sidekiq but your jobs are not running. Which of the following is the most likely cause?config.active_job.queue_adapter = :async in application config to use async adapter by default.self.queue_adapter = :sidekiq to override the default adapter.Pass the test and this pattern moves unknown