Sidekiq.configure_client do |config|
  config.client_middleware do |chain|
    chain.add SidekiqLoggerMiddleware
    # See https://github.com/mhenrixon/sidekiq-unique-jobs/blob/921aaa4efc998b102790d1f4ecce2ebac609e464/README.md#add-the-middleware
    chain.add SidekiqUniqueJobs::Middleware::Client
  end
end

Sidekiq.configure_client do |config|
  config.client_middleware do |chain|
    chain.add SidekiqLoggerMiddleware
    chain.add SidekiqUniqueJobs::Middleware::Client
  end
end

Sidekiq.configure_server do |config|
  config.client_middleware do |chain|
    chain.add SidekiqLoggerMiddleware
    chain.add SidekiqUniqueJobs::Middleware::Client
  end

  config.server_middleware do |chain|
    chain.add SidekiqUniqueJobs::Middleware::Server
  end

  SidekiqUniqueJobs::Server.configure(config)
end

# SidekiqUniqueJobs recommends not testing this behaviour https://github.com/mhenrixon/sidekiq-unique-jobs#uniqueness
SidekiqUniqueJobs.config.enabled = !Rails.env.test?

Add missing server side unique jobs config
Add missing server side unique jobs config

As discussed in the previous commit, when we upgraded
sidekiq-unique-gems to 7.0 we didn't add in all the required config.

Default config was removed from 7.0 of the unique sidekicks
job gem. As a result, you have to manually configure the client and
server middleware
(see https://github.com/mhenrixon/sidekiq-unique-jobs#add-the-middleware)

We missed adding in the server side config. This config deals with
removing a key from Redis after a job has run. This has led to us having
over 7 million keys which should have been expunged still being
persisted.

While you would think this issue would fail fast, and loudly, it
didn't in this situation. This is due to nearly all jobs having uniq
args passed in as discussed in detail in the previous commit. As far as
we can tell, conflicts only occurred on the PublishingAPI
when downtimes were scheduled on Mainstream.

These two issues combined caused surprisingly subtle behaviour which
took a lengthy time to investigate and fix. Around 2 weeks, with a
couple of mobbing sessions and several pairing sessions.
