-
-
Save tjwallace/af131c63a696d7ac0721c6b002bed7c3 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Workers | |
class One | |
include Sidekiq::Worker | |
def perform | |
Sidekiq.logger.info 'Workers::One' | |
batch = Sidekiq::Batch.new | |
batch.on(:success, Two) | |
batch.jobs do | |
Two.perform_async | |
end | |
end | |
end | |
class Two | |
include Sidekiq::Worker | |
def perform | |
Sidekiq.logger.info 'Workers::Two' | |
batch = Sidekiq::Batch.new | |
batch.on(:success, self.class) | |
batch.jobs do | |
Three.perform_async | |
end | |
end | |
def on_success(status, options) | |
Sidekiq.logger.info "Workers::Two Success #{options} #{status.data}" | |
end | |
end | |
class Three | |
include Sidekiq::Worker | |
def perform | |
Sidekiq.logger.info 'Workers::Three' | |
batch = Sidekiq::Batch.new | |
batch.on(:complete, Four) | |
batch.on(:success, Four) | |
batch.jobs do | |
Four.perform_async | |
end | |
end | |
def on_success(status, options) | |
Sidekiq.logger.info "Workers::Three Success #{options} #{status.data}" | |
end | |
end | |
class Four | |
include Sidekiq::Worker | |
@@count = 0 | |
def perform | |
@@count += 1 | |
raise 'First try fridays' if @@count <= 1 | |
Sidekiq.logger.info 'Workers::Four' | |
end | |
def on_complete(status, options) | |
Sidekiq.logger.info "Workers::Four Complete #{options} #{status.data}" | |
end | |
def on_success(status, options) | |
Sidekiq.logger.info "Workers::Four Success #{options} #{status.data}" | |
end | |
end | |
class SomeClass | |
def on_complete(status, options) | |
Sidekiq.logger.info "Overall Complete #{options} #{status.data}" | |
end | |
def on_success(status, options) | |
Sidekiq.logger.info "Overall Success #{options} #{status.data}" | |
end | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
batch = Sidekiq::Batch.new | |
batch.on(:success, Workers::SomeClass, 'uid' => 3) | |
batch.on(:complete, Workers::SomeClass, 'uid' => 3) | |
batch.jobs do | |
Workers::One.perform_async | |
end | |
puts "Overall bid #{batch.bid}" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment