bundle exec sidekiq -C config/sidekiq.yml
TestJob.perform_now(user_id: current_user.id)
TestJob.perform_later(user_id: current_user.id)
TestJob.set(wait: 1.week).perform_later(user_id: current_user.id)
| # config/application.rb | |
| # ... | |
| module FooApp | |
| class Application < Rails::Application | |
| # ... | |
| config.active_job.queue_adapter = :sidekiq | |
| # ... | |
| end | |
| end |
| # app/jobs/application_job.rb | |
| class ApplicationJob < ActiveJob::Base | |
| end |
| # config/initializers/sidekiq.rb | |
| require 'sidekiq' | |
| Sidekiq.configure_server do |config| | |
| config.redis = { url: "redis://#{ENV.fetch('DATA_REDIS_HOST') { 'localhost' }}:6379/1" } | |
| end | |
| Sidekiq.configure_client do |config| | |
| config.redis = { url: "redis://#{ENV.fetch('DATA_REDIS_HOST') { 'localhost' }}:6379/1" } | |
| end | |
| if Rails.env.development? | |
| require 'sidekiq/testing' | |
| Sidekiq::Testing.inline! | |
| end |
| # config/sidekiq.yml | |
| :concurrency: <%= ENV.fetch('SIDEKIQ_CONNECTIONS') { 25 } %> | |
| :queues: | |
| - [critical, 2] | |
| - mailers | |
| - default |
| # app/jobs/test_job.rb | |
| class TestJob < ApplicationJob | |
| queue_as :critical | |
| def perform(user_id:) | |
| user = User.find(user_id) | |
| user.do_something if user | |
| end | |
| end |