Skip to content

Instantly share code, notes, and snippets.

@pramodshinde
Last active March 23, 2018 11:11
Show Gist options
  • Save pramodshinde/f4e1256ac9cc6031fce5 to your computer and use it in GitHub Desktop.
Save pramodshinde/f4e1256ac9cc6031fce5 to your computer and use it in GitHub Desktop.

Revisions

  1. Pramod Shinde revised this gist Jan 3, 2016. 1 changed file with 3 additions and 3 deletions.
    6 changes: 3 additions & 3 deletions user_worker.rb
    Original file line number Diff line number Diff line change
    @@ -23,9 +23,9 @@ def perform
    store delivery_count: 0
    User.find_each do |user|
    # Setting 'at' for progress
    status = retrieve :at
    delivery_count = retrieve :delivery_count
    at (status.to_i + 1), "User: #{user.id}, delivery_count: #{delivery_count}"
    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
  2. Pramod Shinde revised this gist Jan 3, 2016. 1 changed file with 4 additions and 3 deletions.
    7 changes: 4 additions & 3 deletions user_worker.rb
    Original file line number Diff line number Diff line change
    @@ -20,13 +20,14 @@ class UserWorker
    def perform
    # Setting total number of users
    total User.count
    delivery_count = 0
    store delivery_count: 0
    User.find_each do |user|
    # Setting 'at' for progress
    status = retrieve :at
    delivery_count = retrieve :delivery_count
    at (status.to_i + 1), "User: #{user.id}, delivery_count: #{delivery_count}"
    UserMailer.weekly_summary(user).deliver_now
    delivery_count += 1
    store delivery_count: delivery_count
    end
    end
    end
    end
  3. Pramod Shinde created this gist Jan 3, 2016.
    32 changes: 32 additions & 0 deletions user_worker.rb
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,32 @@
    ##
    # 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
    delivery_count = 0
    User.find_each do |user|
    # Setting 'at' for progress
    status = retrieve :at
    at (status.to_i + 1), "User: #{user.id}, delivery_count: #{delivery_count}"
    UserMailer.weekly_summary(user).deliver_now
    delivery_count += 1
    end
    end
    end