Sidekiq on Production

#60 Sidekiq on Production
12/25/2016

Summary

Sidekiq is a Ruby Background Processor that manages its queue with a Redis service. Learn to deploy Sidekiq to your production environment.
4
rails production background processing deployment 6:58 min

Resources

Sidekiq's Website - http://sidekiq.org/
Sidekiq's Github - https://github.com/mperham/sidekiq
Sidekiq's Wiki - https://github.com/mperham/sidekiq/wiki

Summary

Update: Redis Configuration with Sidekiq.

Check out the link below for setting the Redis config if you are using Heroku.
https://github.com/mperham/sidekiq/wiki/Using-Redis#using-an-env-variable

You can set the Redis url using environment variables. This makes configuring Sidekiq on Heroku dead simple.
Set the REDIS_PROVIDER env var to the name of the env var containing the Redis server url. (Example with RedisGreen: set REDIS_PROVIDER=REDISGREEN_URL and Sidekiq will use the value of the REDISGREEN_URL env var when connecting to Redis.)
heroku config:set REDIS_PROVIDER=REDISTOGO_URL
You may also use the generic REDIS_URL which may be set to your own private Redis server.
sidekiq.yml---
:verbose: false
:concurrency: 10
:pidfile: tmp/pids/sidekiq.pid
:queues:
  - [critical, 2]
  - default
  - low

production:
  :concurrency: 25

staging:
  :concurrency: 15
Terminalheroku addons:create redistogo:nano
heroku config:set REDIS_PROVIDER=REDISTOGO_URL

Create Procfile in 
web: bundle exec rails server -p $PORT
worker: bundle exec sidekiq -e production -C config/sidekiq.yml

heroku ps:scale worker=1
/lib/systemd/system/sidekiq.service# Customize this file based on your bundler location, app directory, etc.
# Put this in /usr/lib/systemd/system (CentOS) or /lib/systemd/system (Ubuntu).
# Run:
#   - systemctl enable sidekiq
#   - systemctl {start,stop,restart} sidekiq
#
# This file corresponds to a single Sidekiq process.  Add multiple copies
# to run multiple processes (sidekiq-1, sidekiq-2, etc).
#
# See Inspeqtor's Systemd wiki page for more detail about Systemd:
# https://github.com/mperham/inspeqtor/wiki/Systemd
#
[Unit]
Description=sidekiq
After=syslog.target network.target

[Service]
Type=simple
WorkingDirectory=/home/deploy/060-sidekiq-on-production
ExecStart=/bin/bash -lc 'bundle exec sidekiq -e production -C config/sidekiq.yml'
User=deploy
Group=deploy
UMask=0002

# if we crash, restart
RestartSec=1
#Restart=on-failure
Restart=always

# output goes to /var/log/syslog
StandardOutput=syslog
StandardError=syslog

# This will default to "bundler" if we don't specify it
SyslogIdentifier=sidekiq

[Install]
WantedBy=multi-user.target
Terminalsudo systemctl enable sidekiq.service

# If you have made changes to your service, you may need to reload the daemon
sudo systemctl daemon-reload

sudo service sidekiq start