Skip to content

Instantly share code, notes, and snippets.

@Alex-Karpov-878
Created March 29, 2020 01:01
Show Gist options
  • Save Alex-Karpov-878/699dd59bffc425139bcd4ab0d3a0e9e9 to your computer and use it in GitHub Desktop.
Save Alex-Karpov-878/699dd59bffc425139bcd4ab0d3a0e9e9 to your computer and use it in GitHub Desktop.
Sidekiq with web interface and no retry
# frozen_string_literal: true
require 'sidekiq'
Sidekiq.configure_client { |config| config.redis = { db: 1 } }
require 'sidekiq/web'
run Sidekiq::Web
# bundle exec rackup
source 'https://rubygems.org'
gem 'sidekiq'
gem 'rack'
gem 'sinatra'
# frozen_string_literal: true
# worker.rb
require 'sidekiq'
Sidekiq.configure_client do |config|
config.redis = { db: 1 }
end
Sidekiq.configure_server do |config|
config.redis = { db: 1 }
end
class OurWorker
include Sidekiq::Worker
sidekiq_options retry: 0 # dies if failed
def perform(complexity)
case complexity
when 'super_hard'
puts 'Charging a credit card'
raise 'Whops stuff got bad'
sleep 20
puts 'Really took quite a bit of effort'
when 'hard'
sleep 10
puts 'That was a bit of work'
else
sleep 1
"That wasn't a lot of effort"
end
end
end
# bundle exec sidekiq -r ./worker.rb
# bundle exec irb -r ./worker.rb
## OurWorker.perform_async("easy")
## OurWorker.perform_in(5, "easy")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment