-
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added feature to sort jobs on periodic tab (#7)
- Loading branch information
Showing
9 changed files
with
102 additions
and
7 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,6 +6,7 @@ | |
/pkg/ | ||
/spec/reports/ | ||
/tmp/ | ||
.vscode | ||
|
||
# rspec failure tracking | ||
.rspec_status | ||
|
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 |
---|---|---|
@@ -1,7 +1,7 @@ | ||
PATH | ||
remote: . | ||
specs: | ||
sidekiq-belt (0.3.1) | ||
sidekiq-belt (0.3.2) | ||
sidekiq (> 7.1.4) | ||
|
||
GEM | ||
|
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,24 @@ | ||
# frozen_string_literal: true | ||
|
||
require "sidekiq/web/helpers" | ||
|
||
module Sidekiq | ||
module Belt | ||
module Ent | ||
module PeriodicSort | ||
module SidekiqLoopsPeriodicSort | ||
def each(&block) | ||
@lids.map { |lid| Sidekiq::Periodic::Loop.new(lid) }.sort_by(&:klass).each(&block) | ||
end | ||
end | ||
|
||
def self.use! | ||
require("sidekiq-ent/periodic") | ||
require("sidekiq-ent/periodic/static_loop") | ||
|
||
Sidekiq::Periodic::LoopSet.prepend(Sidekiq::Belt::Ent::PeriodicSort::SidekiqLoopsPeriodicSort) | ||
end | ||
end | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,6 @@ | |
|
||
module Sidekiq | ||
module Belt | ||
VERSION = "0.3.1" | ||
VERSION = "0.3.2" | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
# frozen_string_literal: true | ||
|
||
require "sidekiq" | ||
require "sidekiq/web" | ||
|
||
RSpec.describe(Sidekiq::Belt::Ent::PeriodicSort) do | ||
describe ".each" do | ||
let(:dummy_class) do | ||
Class.new do | ||
def initialize(lids) | ||
@lids = lids | ||
end | ||
end | ||
end | ||
|
||
let(:jobs) do | ||
[ | ||
Sidekiq::Periodic::Loop.new(1, "BClass"), | ||
Sidekiq::Periodic::Loop.new(2, "DClass"), | ||
Sidekiq::Periodic::Loop.new(3, "CClass"), | ||
Sidekiq::Periodic::Loop.new(4, "AClass"), | ||
Sidekiq::Periodic::Loop.new(5, "ZClass") | ||
] | ||
end | ||
|
||
before do | ||
dummy_class.prepend(described_class::SidekiqLoopsPeriodicSort) | ||
stub_const("Sidekiq::Periodic", Module.new) | ||
stub_const("Sidekiq::Periodic::Loop", Struct.new(:id, :klass)) | ||
|
||
allow(Sidekiq::Periodic::Loop).to receive(:new).and_return(jobs[0], jobs[1], jobs[2], jobs[3], jobs[4]) | ||
end | ||
|
||
it "sort periodic jobs by class name" do | ||
expect(dummy_class.new( | ||
[1, 2, 3, 4, 5] | ||
).each.map(&:klass)).to eq(%w[AClass BClass CClass DClass ZClass]) | ||
end | ||
end | ||
|
||
describe ".use!" do | ||
before do | ||
stub_const("Sidekiq::Periodic", Module.new) | ||
stub_const("Sidekiq::Periodic::LoopSet", Class.new) | ||
|
||
allow(described_class).to receive(:require).and_return(true) | ||
allow(Sidekiq::Periodic::LoopSet).to receive(:prepend) | ||
end | ||
|
||
it "injects the code" do | ||
described_class.use! | ||
|
||
expect(described_class).to have_received(:require).with("sidekiq-ent/periodic").once | ||
expect(described_class).to have_received(:require).with("sidekiq-ent/periodic/static_loop").once | ||
|
||
expect(Sidekiq::Periodic::LoopSet).to have_received(:prepend).with(described_class::SidekiqLoopsPeriodicSort) | ||
end | ||
end | ||
end |