breamware / sidekiq-batch

Sidekiq Batch Jobs Implementation

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Question about Batch Callback

jensJJ opened this issue · comments

Thank you for this gem, I was trying to implement Callbacks from my batches, but everything I try does not work. Can someone point me out the mistake? Thanks

I call: Testworker.perform_async("hello")

class TestWorker
  include Sidekiq::Worker
  include Sidekiq::Status::Worker
  sidekiq_options queue: 'default'

  def perform(name)
    batch = Sidekiq::Batch.new
    batch.on(:success, 'TestWorkerCallback#perform')
    batch.jobs do
      TestWorkerTwo.perform_async(name)
    end
  end
end




class TestWorkerCallback
  include Sidekiq::Worker
  include Sidekiq::Status::Worker
  sidekiq_options queue: 'default'

  def perform
    puts "You called TestWorkerCallback as CALLBACK!"
  end
end




class TestWorkerTwo
  include Sidekiq::Worker
  include Sidekiq::Status::Worker
  sidekiq_options queue: 'default'

  def perform(name)
    puts "You called TestWorkerTwo called: #{name}"
  end
end

Hmm, it looks good, can you take a look into integration spec here:
https://github.com/breamware/sidekiq-batch/blob/master/spec/integration/integration.rb

Hello, I get this output:

Started GET "/test" for 127.0.0.1 at 2017-06-09 13:34:36 +0200
  ActiveRecord::SchemaMigration Load (0.4ms)  SELECT `schema_migrations`.* FROM `schema_migrations`
Processing by WelcomeController#test as HTML
{:total=>10, :failures=>0, :pending=>10, :created_at=>"1497008076.0936012", :complete=>false, :failure_info=>[], :parent_bid=>nil}
  Rendered welcome/test.html.erb within layouts/application (1.1ms)
  Rendered layouts/_navigation.html.erb (0.5ms)
  Rendered layouts/_footer.html.erb (0.2ms)
Completed 200 OK in 556ms (Views: 527.3ms | ActiveRecord: 0.0ms)
["BID-pu9BNBBeo93Dhw-callbacks-complete", "BID-pu9BNBBeo93Dhw-jids", "BID-pu9BNBBeo93Dhw", "BID-pu9BNBBeo93Dhw-callbacks-success"]
["BID-pu9BNBBeo93Dhw-callbacks-complete", "BID-pu9BNBBeo93Dhw-jids", "BID-pu9BNBBeo93Dhw", "BID-pu9BNBBeo93Dhw-callbacks-success"]
["BID-pu9BNBBeo93Dhw-callbacks-complete", "BID-pu9BNBBeo93Dhw-jids", "BID-pu9BNBBeo93Dhw", "BID-pu9BNBBeo93Dhw-callbacks-success"]
["BID-pu9BNBBeo93Dhw-callbacks-complete", "BID-pu9BNBBeo93Dhw-jids", "BID-pu9BNBBeo93Dhw", "BID-pu9BNBBeo93Dhw-callbacks-success"]

I have the same problem, callbacks seem to be partially broken
Ruby 2.4.1
Rails 5.1.1
Sidekiq 5.0.3

  class MyCallback
    def on_sucess(status, options)
      puts 'SUCCESS'
    end
    def on_complete(status, options)
      puts 'COMPLETE'
    end
    def on_complete2(status, options)
      puts 'COMPLETE2'
    end
  end

  def perform
    batch = Sidekiq::Batch.new
    batch.on(:success, MyCallback)
    batch.on(:complete, MyCallback)
    batch.jobs do
      EmptyWorker.perform_async
    end
  end

this only outputs COMPLETE, sucess isn't called

And if do something like this

    batch.on(:complete, 'MyCallback#on_complete2')
    batch.on(:complete, MyCallback)

which should be possible according to the spec file it, it doesn't output anything (if i swap those 2 lines it's the same)

update: the 'complete' callback as is this: batch.on(:complete, MyCallback) is also only working in about 90% of the tries

Is this still an issue?

The callback works for 1 layer. But multiple layers break it, I still think.

Callbacks don't work correctly if you build nested batch hierarchy. Top-level callback starts after jobs this level are completed/succeed in spite of low-level batches and their callbacks (top-level batch doesn't monitor child batches). It would be awesome if it works like sidekiq-pro!

Stale issue message

The issue still persist. Is there any workaround to solve it?