-
Active Job is a framework for declaring jobs and making them run on a variety of queuing backends.
-
Rails by default comes with an asynchronous queuing implementation that runs jobs with an in-process thread pool. Jobs will run asynchronously, but any jobs in the queue will be dropped upon restart.
-
Active Job has built-in adapters for queuing backend as:
- Sidekiq
- Resque
- Delayed Job
- Others
-
Sidekiq is a full-featured background processing framework for Ruby.
-
Sidekiq uses threads to handle many jobs at the same time in the same process.
-
Add gem 'sidekiq'
-
Add sidekiq.rb to config/initializers/
Sidekiq.configure_server do |config|
config.redis = { url: 'redis://localhost:6379' }
end
Sidekiq.configure_client do |config|
config.redis = { url: 'redis://localhost:6379' }
end
Redis url format: 'redis://[ip-host]:[port]'
- Setting queue adapter in config/application.rb
module SidekiqApp
class Application < Rails::Application
# Be sure to have the adapter's gem in your Gemfile
# and follow the adapter's specific installation
# and deployment instructions.
config.active_job.queue_adapter = :sidekiq
end
end
- Advance configuration: config/sidekiq.yml
:verbose: true
development:
:concurrency: 1
production:
:concurrency: 20
:queues:
- critical
- default
- mailers
- low
:timeout: 60