Reputation: 11
Class ParentWorker
def perform(team_id)
batch = Sidekiq::Batch.new
batch.on(:complete, self.class, {:team_id => team_id})
batch.jobs do
Team.find(team_id).assets.each do |asset|
AnotherWorker.perform_async(asset.id)
end
end
def on_compete(status, options)
...
end
end
class AnotherWorker
def perform(asset_id)
batch.jobs do
3.times do
ThirdJobWorker.perform_async
end
end
end
end
I all time get the problem that
undefined method `jobs' for nil:NilClass
But the jobs works correct
describe AnotherWorker, type: :job do describe '#perform' do subject { described_class.new.perform(asset_id) }
let(:asset_id) { create(:asset).id }
let(:batch) { instance_double(Sidekiq::Batch) }
before do
allow(Sidekiq::Batch).to receive(:new).and_return(batch)
allow(batch).to receive(:jobs).and_yield
end
it 'call the other jobs' do
expect(batch).to receive(:jobs).and_yield
subject
expect(ThirdJobWorker).to have_enqueued_sidekiq_job(asset_id)
end
end end
Upvotes: 1
Views: 697