Sidekiq is a background job processing system for Ruby applications. It helps run tasks in the background, making your apps faster and more efficient.
Sidekiq uses threads to handle many jobs at the same time in the same process. It does not require Rails but will integrate tightly with Rails to make background processing dead simple.
See the Getting Started wiki page https://github.com/sidekiq/sidekiq/wiki/Getting-Started and follow the simple setup process. You can watch this YouTube playlist https://www.youtube.com/playlist?list=PLjeHh2LSCFrWGT5uVjUuFKAcrcj5kSai1 to learn all about Sidekiq and see its features in action.
For more information, visit https://github.com/sidekiq/sidekiq
SomeJob.set(queue: 'high_priority').perform_async(args)
)Email sending:
class WelcomeEmailJob
include Sidekiq::Job
def perform(user_id)
user = User.find(user_id)
UserMailer.welcome_email(user).deliver_now
end
end
# Enqueue the job
WelcomeEmailJob.perform_async(new_user.id)
Image resizing:
class ResizeImageJob
include Sidekiq::Job
def perform(image_id)
image = Image.find(image_id)
image.resize(800, 600)
image.save
end
end
# Enqueue the job
ResizeImageJob.perform_async(uploaded_image.id)
Data import:
class ImportDataJob
include Sidekiq::Job
def perform(file_path)
CSV.foreach(file_path, headers: true) do |row|
Product.create(row.to_hash)
end
end
end
# Enqueue the job
ImportDataJob.perform_async('products.csv')