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

Incorrect logic in valid? method #62

Closed
hallmatt opened this issue Oct 18, 2022 · 1 comment
Closed

Incorrect logic in valid? method #62

hallmatt opened this issue Oct 18, 2022 · 1 comment

Comments

@hallmatt
Copy link

The valid? method on a batch seems to have incorrect logic.

I specifically ran into an issue invalidating batches since the valid? method always returns false due to an integer now being returned by Redis#exists(key). resque/redis-namespace#195

valid = !Sidekiq.redis { |r| r.exists("invalidated-bid-#{batch.bid}") }

Seems like changing this line in the valid? method would work:

valid = !Sidekiq.redis { |r| r.exists("invalidated-bid-#{batch.bid}") }

to

valid = Sidekiq.redis { |r| r.exists?("invalidated-bid-#{batch.bid}") } > 0

I ran into this with the following example, working to invalidate jobs within a batch. Here's an example job:

class Imports::Payments::ChunkJob < Imports::ChunkBase
  include Sidekiq::Job

  def perform(opts)
    return unless valid_within_batch?
  end
end

I run the batch to get things started and I expect the batch to fully run, but valid_within_batch? always returns false. I threw a debugger in the job and found the following:

(ruby) Sidekiq.redis { |r| r.exists("invalidated-bid-#{batch.bid}") }
0 
(ruby) !Sidekiq.redis { |r| r.exists("invalidated-bid-#{batch.bid}") }
false 
@github-actions
Copy link

Stale issue message

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant