Provides a unified set of configurations and behaviours when using Sidekiq in GOV.UK applications.
What does govuk_sidekiq
do for you?
- Makes sure Sidekiq can connect to Redis correctly, using the default environment variables (these are set in govuk-puppet).
- Makes sure that the correct HTTP headers are passed on to gds-api-adapters. This means that for each request a unique ID (govuk_request_id) will be passed on to downstream applications. Read more about request tracing.
- Makes sure that we use JSON logging, so that Sidekiq logs will end up properly in Kibana.
- Sends activity stats to Statsd, so that you can make pretty graphs of activity in Grafana or Graphite. See the Rummager dashboards for an example.
- Configures Sidekiq so that exceptions will be sent to our Errbit instance.
# Gemfile
gem "govuk_sidekiq", "~> VERSION"
# config/sidekiq.yml
---
:concurrency: 2
This file also allows you to configure queues with priority. See the Sidekiq wiki for available options.
This is what puppet uses to create the process.
# Procfile
worker: bundle exec sidekiq -C ./config/sidekiq.yml
- Set
REDIS_HOST
andREDIS_PORT
variables.GOVUK_APP_NAME
should also be set, but this is already done by the defaultgovuk::app::config
. - Make sure puppet creates and starts the Procfile worker.
There's no step-by-step guide for this, but you can copy the config from collections-publisher.
Make sure you restart the worker after deploying by adding a hook to the capistrano scripts in govuk-app-deployment. Otherwise the worker will keep running old code.
# your-application/config/deploy.rb
after "deploy:restart", "deploy:restart_procfile_worker"
This makes sure that your development environment behaves like production.
See the Pinfile and Procfile for examples.
See the opsmanual for a step-by-step guide: HOWTO: Add sidekiq-monitoring to your application
You can use normal Sidekiq jobs:
# app/workers/hard_worker.rb
class HardWorker
include Sidekiq::Worker
def perform(name, count)
# do something
end
end
Note that the convention is to use app/workers
as the directory for your workers.
See Sidekiq testing documentation on how to test Sidekiq workers.
Because of the way we use middleware, you may see errors that indicate that
your job is called with the wrong number of arguments. To set up testing
correctly, replace require 'sidekiq/testing'
with:
require 'govuk_sidekiq/testing'
See https://github.com/alphagov/styleguides/blob/master/rubygems.md#versioning