😈 SidekiqLast updated on Dec 4, 2020 2 min read rubySidekiqSimple, efficient background processing for Ruby. 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.Sidekiq…001.2 first job# work.rbreiqure ‘sidekiq'Sidekiq.configure_client do |config| config.redis = {db: 1}endSidekiq.configure_servier do |config| config.redis = {db: 1}endclass OurWorker incldue Sidekiq::Worker def perform(complexity) case complexity when “super_hand" sleep 20 puts “Really took quite a bit of effort" end when “ard" sleep 10 puts “That was a bit of work" else sleep 1 puts “That wasn’t a lot of effort" endend# work.rb…# Gemfilesource “https://rugygems.org"gem “sidekiq"bundle# Gemfile…bundle exec sidekiq -r ./worker.rbbundle exec irb -r ./worker.rbOurWorker.perform_async(“easy”)OurWorker.perform_async(“hanrd”)OurWorker.perform_in(5, “easy”)bundle exec sidekiq -r ./worker.rb…001.4 Error handling# work.rbreiqure ‘sidekiq'Sidekiq.configure_client do |config| config.redis = {db: 1}endSidekiq.configure_servier do |config| config.redis = {db: 1}endclass OurWorker incldue Sidekiq::Worker sidekiq_options retry: 0 def perform(complexity) case complexity when “super_hand" puts “charging a credit card…“ raise “Woops stuff got bad" puts “Really took quite a bit of effort" end when “ard" sleep 10 puts “That was a bit of work" else sleep 1 puts “That wasn’t a lot of effort" endend# work.rb…# Gemfilesource “https://rugygems.org"gem “sidekiq"gem “rack"gem “sinatra"buhndle# Gemfile…bundle exec sidekiq -r ./worker.rbbundle exec irb -r ./worker.rbOurWorker.perform_async(“easy”)OurWorker.perform_async(“hanrd”)OurWorker.perform_in(5, “easy”)bundle exec sidekiq -r ./worker.rb…# config.rureiqure ‘sidekiq'Sidekiq.configure_client do |config| config.redis = { db: 1 }endreiqure ‘sidekiq/web'run Sidekiq::Webrackup# config.ru…Viewer does not support full SVG 1.1sidekiq snippetsZane ZhengFull Stack (Ruby on Rails) / DevopsAn Full Stack / Devops with JS, Ruby, Linux, JAMStack, MicroServices.Related🤐 CMS Essential👻 Ruby Enumerable🤡 Ruby on Rails Gems List