README.md in sidekiq-unique-jobs-7.0.0.beta25 vs README.md in sidekiq-unique-jobs-7.0.0.beta26

- old
+ new

@@ -31,19 +31,31 @@ - [Until Expired](#until-expired) - [Until And While Executing](#until-and-while-executing) - [While Executing](#while-executing) - [Custom Locks](#custom-locks) - [Conflict Strategy](#conflict-strategy) -- [lib/strategies/my_custom_strategy.rb](#libstrategiesmy_custom_strategyrb) -- [For rails application](#for-rails-application) -- [config/initializers/sidekiq_unique_jobs.rb](#configinitializerssidekiq_unique_jobsrb) -- [For other projects, whenever you prefer](#for-other-projects-whenever-you-prefer) -- [this goes in your initializer](#this-goes-in-your-initializer) -- [app/config/routes.rb](#appconfigroutesrb) -- [app/workers/bad_worker.rb](#appworkersbad_workerrb) -- [spec/workers/bad_worker_spec.rb](#specworkersbad_worker_specrb) -- [OR](#or) + - [log](#log) + - [raise](#raise) + - [reject](#reject) + - [replace](#replace) + - [Reschedule](#reschedule) + - [Custom Strategies](#custom-strategies) +- [Usage](#usage) + - [Finer Control over Uniqueness](#finer-control-over-uniqueness) + - [After Unlock Callback](#after-unlock-callback) + - [Logging](#logging) + - [Cleanup Dead Locks](#cleanup-dead-locks) + - [Other Sidekiq gems](#other-sidekiq-gems) + - [sidekiq-global_id](#sidekiq-global_id) +- [Debugging](#debugging) + - [Sidekiq Web](#sidekiq-web) + - [Show Locks](#show-locks) + - [Show Lock](#show-lock) +- [Communication](#communication) +- [Testing](#testing) + - [Unique Sidekiq Configuration](#unique-sidekiq-configuration) + - [Uniqueness](#uniqueness) - [Contributing](#contributing) - [Contributors](#contributors) <!-- /MarkdownTOC --> @@ -104,10 +116,12 @@ ## Global Configuration The gem supports a few different configuration options that might be of interest if you run into some weird issues. +Configure SidekiqUniqueJobs in an initializer or the sidekiq initializer on application startup. + ```ruby SidekiqUniqueJobs.configure do |config| config.debug_lua = true config.lock_info = true config.lock_ttl = 10.minutes @@ -187,10 +201,18 @@ On the other hand if I increase it to 10 000 orphaned locks per cleanup (`reaper_count: 10_0000`) then redis starts throwing: > BUSY Redis is busy running a script. You can only call SCRIPT KILL or SHUTDOWN NOSAVE. (Redis::CommandError) +If you want to disable the reaper set it to `:none`, `nil` or `false`. Actually, any value that isn't `:ruby` or `:lua` will disable the reaping. + +```ruby +SidekiqUniqueJobs.config.reaper = :none +SidekiqUniqueJobs.config.reaper = nil +SidekiqUniqueJobs.config.reaper = false +``` + ### reaper_count ```ruby SidekiqUniqueJobs.config.reaper_count #=> 1_000 ``` @@ -381,15 +403,13 @@ You can refer on all the locks defined in `lib/sidekiq_unique_jobs/lock/*.rb`. In order to make it available, you should call in your project startup: -```ruby -# For rails application -# config/initializers/sidekiq_unique_jobs.rb -# For other projects, whenever you prefer +(For rails application config/initializers/sidekiq_unique_jobs.rb or other projects, wherever you prefer) +```ruby SidekiqUniqueJobs.configure do |config| config.add_lock :my_custom_lock, Locks::MyCustomLock end ``` @@ -406,11 +426,13 @@ The last one is log which can be be used with the lock `UntilExecuted` and `UntilExpired`. Now we write a log entry saying the job could not be pushed because it is a duplicate of another job with the same arguments. It is possible for locks to have different conflict strategy for the client and server. This is useful for `:until_and_while_executing`. ```ruby -sidekiq_options lock: :until_and_while_executing, on_conflict: { client: :log, server: :reject } +sidekiq_options lock: :until_and_while_executing, + on_conflict: { client: :log, server: :reject } +``` ### log ```ruby sidekiq_options on_conflict: :log @@ -472,15 +494,13 @@ You can refer to all the strategies defined in `lib/sidekiq_unique_jobs/on_conflict`. In order to make it available, you should call in your project startup: -```ruby -# For rails application -# config/initializers/sidekiq_unique_jobs.rb -# For other projects, whenever you prefer +(For rails application config/initializers/sidekiq_unique_jobs.rb for other projects, wherever you prefer) +```ruby SidekiqUniqueJobs.configure do |config| config.add_strategy :my_custom_strategy, Strategies::MyCustomStrategy end ``` @@ -576,10 +596,11 @@ def after_unlock # block has yielded and lock is released end ... end. +``` ### Logging To see logging in sidekiq when duplicate payload has been filtered out you can enable on a per worker basis using the sidekiq options. The default value is false @@ -608,11 +629,10 @@ ``` Starting in v5.1, Sidekiq can also fire a global callback when a job dies: ```ruby -# this goes in your initializer Sidekiq.configure_server do |config| config.death_handlers << ->(job, _ex) do digest = job['unique_digest'] SidekiqUniqueJobs::Digests.delete_by_digest(digest) if digest end @@ -646,11 +666,11 @@ ### Sidekiq Web To use the web extension you need to require it in your routes. ```ruby -# app/config/routes.rb +#app/config/routes.rb require 'sidekiq_unique_jobs/web' mount Sidekiq::Web, at: '/sidekiq' ``` There is no need to `require 'sidekiq/web'` since `sidekiq_unique_jobs/web` @@ -677,18 +697,18 @@ Since v7 it is possible to perform some simple validation against your workers sidekiq_options. What it does is scan for some issues that are known to cause problems in production. Let's take a _bad_ worker: ```ruby -# app/workers/bad_worker.rb +#app/workers/bad_worker.rb class BadWorker sidekiq_options lock: :while_executing, on_conflict: :replace end -# spec/workers/bad_worker_spec.rb +#spec/workers/bad_worker_spec.rb require "sidekiq_unique_jobs/testing" -# OR +#OR require "sidekiq_unique_jobs/rspec/matchers" RSpec.describe BadWorker do specify { expect(described_class).to have_valid_sidekiq_options } end