-
-
Notifications
You must be signed in to change notification settings - Fork 277
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Fix Reaper startup * Fix viewing changelogs * Adds the missing configuration * Make less smelly * Move to a separate server class * Mandatory rubocop commit * Code smells * Adds test coverage * Mandatory rubocop commit * Better tests for web helpers * Mandatory rubocop commit * Skip death handler spec when sidekiq doesn't have it * Code smells * Mandatory rubocop commit
- Loading branch information
Showing
11 changed files
with
205 additions
and
44 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
# frozen_string_literal: true | ||
|
||
module SidekiqUniqueJobs | ||
# The unique sidekiq middleware for the server processor | ||
# | ||
# @author Mikael Henriksson <mikael@mhenrixon.com> | ||
class Server | ||
DEATH_HANDLER ||= (lambda do |job, _ex| | ||
return unless (digest = job["lock_digest"]) | ||
|
||
SidekiqUniqueJobs::Digests.new.delete_by_digest(digest) | ||
end).freeze | ||
# | ||
# Configure the server middleware | ||
# | ||
# | ||
# @return [Sidekiq] the sidekiq configuration | ||
# | ||
def self.configure(config) | ||
config.on(:startup) { start } | ||
config.on(:shutdown) { stop } | ||
|
||
return unless config.respond_to?(:death_handlers) | ||
|
||
config.death_handlers << death_handler | ||
end | ||
|
||
def self.start | ||
SidekiqUniqueJobs::UpdateVersion.call | ||
SidekiqUniqueJobs::UpgradeLocks.call | ||
SidekiqUniqueJobs::Orphans::Manager.start | ||
end | ||
|
||
def self.stop | ||
SidekiqUniqueJobs::Orphans::Manager.stop | ||
end | ||
|
||
# | ||
# A death handler for dead jobs | ||
# | ||
# | ||
# @return [lambda] | ||
# | ||
def self.death_handler | ||
DEATH_HANDLER | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
# frozen_string_literal: true | ||
|
||
RSpec.describe SidekiqUniqueJobs::Server do | ||
describe ".configure" do | ||
subject(:configure) { described_class.configure(config) } | ||
|
||
let(:config) { Sidekiq } | ||
|
||
before do | ||
allow(config).to receive(:on).with(:startup).and_call_original | ||
allow(config).to receive(:on).with(:shutdown).and_call_original | ||
allow(config.death_handlers).to receive(:<<).and_call_original if Sidekiq.respond_to?(:death_handlers) | ||
end | ||
|
||
it "configures startup" do | ||
configure | ||
|
||
expect(config).to have_received(:on).with(:startup) | ||
expect(config).to have_received(:on).with(:shutdown) | ||
|
||
if Sidekiq.respond_to?(:death_handlers) | ||
expect(config.death_handlers).to have_received(:<<) | ||
.with(described_class.death_handler) | ||
end | ||
end | ||
end | ||
|
||
describe ".start" do | ||
subject(:start) { described_class.start } | ||
|
||
before do | ||
allow(SidekiqUniqueJobs::UpdateVersion).to receive(:call).and_return(true) | ||
allow(SidekiqUniqueJobs::UpgradeLocks).to receive(:call).and_return(true) | ||
allow(SidekiqUniqueJobs::Orphans::Manager).to receive(:start).and_return(true) | ||
end | ||
|
||
it "starts processes in the background" do | ||
start | ||
|
||
expect(SidekiqUniqueJobs::UpdateVersion).to have_received(:call) | ||
expect(SidekiqUniqueJobs::UpgradeLocks).to have_received(:call) | ||
expect(SidekiqUniqueJobs::Orphans::Manager).to have_received(:start) | ||
end | ||
end | ||
|
||
describe ".stop" do | ||
subject(:stop) { described_class.stop } | ||
|
||
before do | ||
allow(SidekiqUniqueJobs::Orphans::Manager).to receive(:stop).and_return(true) | ||
end | ||
|
||
it "starts processes in the background" do | ||
stop | ||
|
||
expect(SidekiqUniqueJobs::Orphans::Manager).to have_received(:stop) | ||
end | ||
end | ||
|
||
describe ".death_handler" do | ||
subject(:death_handler) { described_class.death_handler } | ||
|
||
let(:item) { { "lock_digest" => digest } } | ||
let(:digest) { "uniquejobs:abcdefab" } | ||
let(:digests) { SidekiqUniqueJobs::Digests.new } | ||
|
||
before do | ||
allow(digests).to receive(:delete_by_digest).and_return(true) | ||
allow(SidekiqUniqueJobs::Digests).to receive(:new).and_return(digests) | ||
end | ||
|
||
it "deletes digests for dead jobs" do | ||
death_handler.call(item, nil) | ||
|
||
expect(digests).to have_received(:delete_by_digest).with(digest) | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters