Skip to content

Instantly share code, notes, and snippets.

@wilforlan
Created June 14, 2018 00:16
Show Gist options
  • Save wilforlan/e364582f0a39400ab7f2a081321ef86f to your computer and use it in GitHub Desktop.
Save wilforlan/e364582f0a39400ab7f2a081321ef86f to your computer and use it in GitHub Desktop.
Example of Background Process using Sidekiq in Rails
# gem install sidekiq
# config/sidekiq.yml
---
:environment: production
:verbose: false
:pidfile: ./tmp/pids/sidekiq.pid
:concurrency: 4
:logfile: ./log/sidekiq.log
:queues:
- default
- ts_delta
#app/workers/notification_worker.rb
class NotificationWorker
include Sidekiq::Worker
sidekiq_options :retry => false # not try again if failed, should use max tries if false
def perform(type, *args)
send(type, *args)
end
private
def send_review_notification(author, reviewer, pr_id)
# do something here
end
...
end
# app/controller/actions_controller.rb
...
def set_reviewers
NotificationWorker.perform_async(:send_review_notification, current_user.id, reviewers_id, pr_id)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment