Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Sample template sidekiq worker with sidekiq-status
##
# Obvious steps to follow before adding this template worker to your Rails Application
# 1. Add 'gem sidekiq-status' to Gemfile
# 2. bundle install
# 3. include Sidekiq::Status::Worker in your worker if you want tarck the progrees of your worker.
# 4. Setup Sidekiq Web & sidekiq-status Web UI's
# a. Sidekiq Web UI
# a1. Add gem 'sinatra', :require => nil to Gemfile
# a2. Add follwing to routes
# require 'sidekiq/web'
# mount Sidekiq::Web => '/sidekiq'
# b. Add folliwing line to routes
# require 'sidekiq-status/web'
# 5. As this just a template, Please make neccessary chnages to fit it in your Rails Application.
## Template Sidekiq Worker with sidekiq-status
class UserWorker
include Sidekeq::Worker
include Sidekiq::Status::Worker #Important
def perform
# Setting total number of users
total User.count
store delivery_count: 0
User.find_each do |user|
# Setting 'at' for progress
status = retrieve(:at).to_i
delivery_count = retrieve(:delivery_count).to_i
at (status + 1), "User: #{user.id}, delivery_count: #{delivery_count}"
UserMailer.weekly_summary(user).deliver_now
delivery_count += 1
store delivery_count: delivery_count
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.