diff --git a/README.md b/README.md index 1f0ec48e2..db253e8ef 100644 --- a/README.md +++ b/README.md @@ -29,6 +29,7 @@ * [Finer Control over Uniqueness](#finer-control-over-uniqueness) * [After Unlock Callback](#after-unlock-callback) * [Logging](#logging) + * [Cleanup Dead Locks](#cleanup-dead-locks) * [Debugging](#debugging) * [Sidekiq Web](#sidekiq-web) * [Show Unique Digests](#show-unique-digests) @@ -353,6 +354,29 @@ class UniqueJobWithFilterMethod end ``` +### Cleanup Dead Jobs + +For sidekiq versions before 5.1 a `sidekiq_retries_exhausted` block is required per worker class. + +```ruby +class MyWorker + sidekiq_retries_exhausted do |msg, _ex| + SidekiqUniqueJobs::Digests.delete_by(digest: msg['unique_digest']) if msg['unique_digest'] + end +end +``` + +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 + SidekiqUniqueJobs::Digests.delete_by(digest: job['unique_digest']) if job['unique_digest'] + end +end +``` + ## Debugging There are two ways to display and remove keys regarding uniqueness. The console way and the command line way. diff --git a/lib/sidekiq_unique_jobs/web/helpers.rb b/lib/sidekiq_unique_jobs/web/helpers.rb index 85761dc24..dbe916262 100644 --- a/lib/sidekiq_unique_jobs/web/helpers.rb +++ b/lib/sidekiq_unique_jobs/web/helpers.rb @@ -5,10 +5,6 @@ module Web module Helpers VIEW_PATH = File.expand_path('../web/views', __dir__) - def filtering(pattern, count) - SidekiqUniqueJobs::Util.keys(pattern, count) - end - def unique_template(name) File.open(File.join(VIEW_PATH, "#{name}.erb")).read end diff --git a/rails_example/.gitignore b/rails_example/.gitignore index 5b61ab0e2..baa4a9c92 100644 --- a/rails_example/.gitignore +++ b/rails_example/.gitignore @@ -11,3 +11,6 @@ /log/* !/log/.keep /tmp + +# Ignore master key for decrypting credentials and more. +/config/master.key diff --git a/rails_example/config/credentials.yml.enc b/rails_example/config/credentials.yml.enc new file mode 100644 index 000000000..0d12beedb --- /dev/null +++ b/rails_example/config/credentials.yml.enc @@ -0,0 +1 @@ +5Z9kpiujtSvYTo0oVBzG8XPabCc5wRxo16cGro+mSgdOslR2hjejEZfh6D3eM0S9eq0afAJ7yR/vOR/1L/ACREZ+uXxh72n2YwuOSveaSz0291pfHrUSCZMjo0oU03znya7lQvopYdPpFUaIsD+wBYM2s/9ItBUoJBMex8ZrqRjzjvJq+EvO/O5WgObBvNtRMyQBfrgOhpSuMLye2dgrtB7LFKSM7cTUrj1XFVg4bVertSrQIUjGZXAKW5yKI4Xtqx7hstEMyucFPXjjwHiNAKAugecg3ttG3H2AvAq6AFQC5qJyBcAZFBPsmpnoUEv+8msGvVp9s4N/plnGz3Vh43e0o3z1t9BXrcYiYyR+Eu/scvnmbf7NTuDNeyoG7PxH5mXWiXJUfqnu8wRBs4zxOy1Ub5DAz4FIx7YT--evpxuoVG2tMsVyuM--GK3U5kJh/q1AexJTiGkrvA== \ No newline at end of file diff --git a/rails_example/config/database.yml b/rails_example/config/database.yml index 2bffd9814..826b3c7af 100644 --- a/rails_example/config/database.yml +++ b/rails_example/config/database.yml @@ -3,7 +3,7 @@ defaults: &defaults adapter: postgresql host: <%= ENV.fetch('DB_HOST') { 'localhost' } %> port: <%= ENV.fetch('DB_PORT') { 5432 } %> - username: <%= ENV.fetch('DB_USERNAME') { 'mhenrixon' } %> + username: <%= ENV.fetch('DB_USERNAME') { `whoami` } %> password: <%= ENV.fetch('DB_PASSWORD') { nil } %> pool: <%= ENV.fetch('DB_POOL') { 25 } %> timeout: <%= ENV.fetch('DB_TIMEOUT') { 5000 } %> @@ -17,3 +17,7 @@ test: <<: *defaults database: rails_example_test +production: + <<: *defaults + database: rails_example_prod +