Last active
March 23, 2018 11:11
-
-
Save pramodshinde/f4e1256ac9cc6031fce5 to your computer and use it in GitHub Desktop.
Sample template sidekiq worker with sidekiq-status
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
## | |
# 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