Skip to content

Commit

Permalink
redis-client: Fix ZADD compatibility (#5387)
Browse files Browse the repository at this point in the history
  • Loading branch information
casperisfine committed Jun 13, 2022
1 parent 8269205 commit 2b58b74
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 8 deletions.
2 changes: 1 addition & 1 deletion lib/sidekiq/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ def raw_push(payloads)

def atomic_push(conn, payloads)
if payloads.first.key?("at")
conn.zadd("schedule", *payloads.map { |hash|
conn.zadd("schedule", payloads.flat_map { |hash|
at = hash.delete("at").to_s
[at, Sidekiq.dump_json(hash)]
})
Expand Down
17 changes: 10 additions & 7 deletions test/test_client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -271,13 +271,16 @@ def perform(arg)
assert_equal 1_000, jids.size
end

it "can push jobs scheduled at different times" do
first_at = Time.new(2019, 1, 1)
second_at = Time.new(2019, 1, 2)
jids = Sidekiq::Client.push_bulk("class" => QueuedWorker, "args" => [[1], [2]], "at" => [first_at.to_f, second_at.to_f])
(first_jid, second_jid) = jids
assert_equal first_at, Sidekiq::ScheduledSet.new.find_job(first_jid).at
assert_equal second_at, Sidekiq::ScheduledSet.new.find_job(second_jid).at
[1, 2, 3].each do |job_count|
it "can push #{job_count} jobs scheduled at different times" do
times = job_count.times.map { |i| Time.new(2019, 1, i + 1) }
args = job_count.times.map { |i| [i] }

jids = Sidekiq::Client.push_bulk("class" => QueuedWorker, "args" => args, "at" => times.map(&:to_f))

assert_equal job_count, jids.size
assert_equal times, jids.map { |jid| Sidekiq::ScheduledSet.new.find_job(jid).at }
end
end

it "can push jobs scheduled using ActiveSupport::Duration" do
Expand Down

0 comments on commit 2b58b74

Please sign in to comment.