Skip to content

Commit

Permalink
Merge pull request #89 from compliance-innovations/sidekiq7-fix
Browse files Browse the repository at this point in the history
Update for Sidekiq 7
  • Loading branch information
nglx authored Mar 7, 2024
2 parents 5496f04 + 1374e07 commit f2ef028
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 13 deletions.
18 changes: 16 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -1,16 +1,30 @@
name: CI

on: [push, pull_request]
on: [pull_request, workflow_dispatch]

jobs:
test:
env:
REDIS_HOST: 'redis'

runs-on: ubuntu-latest
services:
redis:
image: redis
# Set health checks to wait until redis has started
options: >-
--health-cmd "redis-cli ping"
--health-interval 10s
--health-timeout 5s
--health-retries 5
ports:
# Maps port 6379 on service container to the host
- 6379:6379

strategy:
fail-fast: false
matrix:
ruby: ["2.5", "2.6", "2.7", "3.0", "3.1", ruby-head]
ruby: ["3.0", "3.1", "3.2", ruby-head]

steps:
- uses: actions/checkout@v2
Expand Down
6 changes: 3 additions & 3 deletions lib/sidekiq/batch.rb
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ def parent
end

def valid?(batch = self)
valid = !Sidekiq.redis { |r| r.exists("invalidated-bid-#{batch.bid}") }
valid = Sidekiq.redis { |r| r.exists("invalidated-bid-#{batch.bid}") }.zero?
batch.parent ? valid && valid?(batch.parent) : valid
end

Expand Down Expand Up @@ -248,7 +248,7 @@ def enqueue_callbacks(event, bid)
already_processed, _, callbacks, queue, parent_bid, callback_batch = Sidekiq.redis do |r|
r.multi do |pipeline|
pipeline.hget(batch_key, event_name)
pipeline.hset(batch_key, event_name, true)
pipeline.hset(batch_key, event_name, 'true')
pipeline.smembers(callback_key)
pipeline.hget(batch_key, "callback_queue")
pipeline.hget(batch_key, "parent_bid")
Expand Down Expand Up @@ -292,7 +292,7 @@ def enqueue_callbacks(event, bid)
else
# Otherwise finalize in sub batch complete callback
cb_batch = self.new
cb_batch.callback_batch = true
cb_batch.callback_batch = 'true'
Sidekiq.logger.debug {"Adding callback batch: #{cb_batch.bid} for batch: #{bid}"}
cb_batch.on(:complete, "Sidekiq::Batch::Callback::Finalize#dispatch", opts)
cb_batch.jobs do
Expand Down
1 change: 0 additions & 1 deletion sidekiq-batch.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,4 @@ Gem::Specification.new do |spec|
spec.add_development_dependency "bundler", "~> 2.1"
spec.add_development_dependency "rake", "~> 13.0"
spec.add_development_dependency "rspec", "~> 3.0"
spec.add_development_dependency "fakeredis", "~> 0.8.0"
end
2 changes: 1 addition & 1 deletion spec/sidekiq/batch/middleware_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@
end

describe Sidekiq::Batch::Middleware do
let(:config) { class_double(Sidekiq) }
let(:config) { instance_double(Sidekiq::Config) }
let(:client_middleware) { double(Sidekiq::Middleware::Chain) }

context 'client' do
Expand Down
8 changes: 4 additions & 4 deletions spec/sidekiq/batch_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ def was_performed; end
Sidekiq::Batch.process_failed_job(bid, 'failed-job-id')
Sidekiq::Batch.process_failed_job(bid, failed_jid)
failed = Sidekiq.redis { |r| r.smembers("BID-#{bid}-failed") }
expect(failed).to eq(['xxx', 'failed-job-id'])
expect(failed).to eq(['failed-job-id', 'xxx'])
end
end
end
Expand Down Expand Up @@ -245,7 +245,7 @@ def was_performed; end
it 'returns and does not enqueue callbacks' do
batch = Sidekiq::Batch.new
batch.on(event, SampleCallback)
Sidekiq.redis { |r| r.hset("BID-#{batch.bid}", event, true) }
Sidekiq.redis { |r| r.hset("BID-#{batch.bid}", event, 'true') }

expect(Sidekiq::Client).not_to receive(:push)
Sidekiq::Batch.enqueue_callbacks(event, batch.bid)
Expand Down Expand Up @@ -290,8 +290,8 @@ def was_performed; end
expect(Sidekiq::Client).to receive(:push_bulk).with(
'class' => Sidekiq::Batch::Callback::Worker,
'args' => [
['SampleCallback2', event.to_s, opts2, batch.bid, nil],
['SampleCallback', event.to_s, opts, batch.bid, nil]
['SampleCallback', event.to_s, opts, batch.bid, nil],
['SampleCallback2', event.to_s, opts2, batch.bid, nil]
],
'queue' => 'default'
)
Expand Down
8 changes: 6 additions & 2 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,9 @@
SimpleCov.start

$LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
require 'fakeredis/rspec'
require 'sidekiq/batch'

redis_opts = { url: "redis://127.0.0.1:6379/1" }
redis_opts[:driver] = Redis::Connection::Memory if defined?(Redis::Connection::Memory)

Sidekiq.configure_client do |config|
config.redis = redis_opts
Expand All @@ -19,6 +17,12 @@
RSpec.configure do |config|
config.filter_run focus: true
config.run_all_when_everything_filtered = true

config.before do
Sidekiq.redis do |redis|
redis.flushdb
end
end
end

Dir[File.dirname(__FILE__) + "/support/**/*.rb"].each {|f| require f }

0 comments on commit f2ef028

Please sign in to comment.