Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add sidekiq_option for on-conflict-reschedule perform_in time #813

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion lib/sidekiq_unique_jobs/on_conflict/reschedule.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def initialize(item, redis_pool = nil)
# This will mess up sidekiq stats because a new job is created
def call
if sidekiq_job_class?
if job_class.set(queue: item["queue"].to_sym).perform_in(5, *item[ARGS])
if job_class.set(queue: item["queue"].to_sym).perform_in(schedule_in, *item[ARGS])
reflect(:rescheduled, item)
else
reflect(:reschedule_failed, item)
Expand All @@ -30,6 +30,10 @@ def call
reflect(:unknown_sidekiq_worker, item)
end
end

def schedule_in
job_class.get_sidekiq_options["schedule_in"] || 5
end
end
end
end
15 changes: 15 additions & 0 deletions spec/sidekiq_unique_jobs/on_conflict/reschedule_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,21 @@
allow(UniqueJobOnConflictReschedule).to receive(:perform_in).and_call_original
end

context "when schedule_in is set to ten seconds" do
around do |block|
UniqueJobOnConflictReschedule.use_options(schedule_in: 10) do
block.call
end
end

it "schedules a job ten seconds from now" do
expect { call }.to change { schedule_count }.by(1)

expect(UniqueJobOnConflictReschedule).to have_received(:perform_in)
.with(10, *item["args"])
end
end

it "schedules a job five seconds from now" do
expect { call }.to change { schedule_count }.by(1)

Expand Down
Loading